Replace text with regexp in sublime text - regex

How I replace text with part old text in sublime text.
I have:
<span class="foo">some text</span>
<span class="foo">another text</span>
I want:
<b>some text</b>
<b>another text</b>
Search
<span class="foo">(\w+)</span>
and replace with
{1}
don't work

Search: <span class="foo">(.*?)</span>
Replace: <b>$1</b>

Use $1 instead of {1} for replacing text

Related

How to remove li tags with in Particular DIV tag in notepad ++ using regex

I have content like below
enter code here
<div class="content1">
<ul>
<li>line1</li>
<li>line2</li>
<li>line3</li>
</ul>
</div>
<div class="content2">
<ul>
<li>line4</li>
<li>line5</li>
<li>line6</li>
</ul>
</div>
I want to strip all li tags within and retain contents inside it. like below
enter code here
<div class="content1">
<ul>
line1
line2
line3
</ul>
</div>
<div class="content2">
<ul>
<li>line4</li>
<li>line5</li>
<li>line6</li>
</ul>
</div>
I have about 500 html files to edit.Is there any Regex code to achieve this in notepad++.
You can use a regex like this
<li>(.*?)<\/li>
With the replacement string:
$1
Working demo
The regex to match those tags are
\<li\>
\<\/li\>
The backslashes are used to treat special characters as 'normal' characters.
If you use terminal you can use stream edit which is
sed 's/\<li\>//' input.txt > output.txt
But in notepad++ i believe you can ctrl find and replace

Regex to replace all html tag except br and p tag perl

I have a string in that i will be getting so many html tag i want to replace them with space .How can we do this please suggest me .This is my string :
Wrong html <a> </I> <p>My paragraph</p> <i>Italics</i> <p class="blue">second</p> and the string is <br> after that test.
I have tried this but this is not working accordingly:
$string =~ s/(<((?!br|p)[^>]+)>)//ig;
You need to deal with closing tags:
use Modern::Perl;
my $str = 'Wrong html <a> </I> <p>My paragraph</p> <i>Italics</i> <p class="blue">second</p> and the string is <br> after that test.';
$str =~ s~<(?!/?\s*br|/?\s*p)[^>]+>~~ig;
say $str;
You could also use package HTML::StripTags:
use HTML::StripTags qw(strip_tags);
my $str = 'Wrong html <a> </I> <p>My paragraph</p> <i>Italics</i> <p class="blue">second</p> and the string is <br> after that test.';
my $allowed_tags = '<p><br>';
say strip_tags( $str, $allowed_tags );
In your regular expression, you did not mention substitution character or delimiter. In your case, you should substitute with space.
Regular expression is:
$msg =~s/(<((?!br|p)[^>]+)>)/ /ig;

PowerShell regular expression to get all the HTML tags

I have a string with HTML tags. I have to write PowerShell script to split this string using regular expression for HTML tags both opening and closing. I have tried many times but with no luck.
<([A-Z][A-Z0-9])[^>]>
I have tried this for opening tags. But it only removes the '<' and '>' from string not the whole tag.
My string is something like this:
<Div id="div1">
<Div>
some text inside.
</Div>
<font>this is text inside font.
</font>
<h1>this is h1 text.
</h1>
<p>
This is a new paragraph.
</p>
</Div>
My desired output is: some text inside. This is text inside font. this is h1 text. This is a new paragraph.
Not sure how you're doing your split, but it shouldn't be that difficult:
$Text =
#'
<Div id="div1">
<Div>
some text inside.
</Div>
<font>this is text inside font.
</font>
<h1>this is h1 text.
</h1>
<p>
This is a new paragraph.
</p>
</Div>
'#
$text -split '<.+?>' -match '\S'
some text inside.
this is text inside font.
this is h1 text.
This is a new paragraph.

Automatically wrap acronyms or words in caps with <span>

I’d like to format all acronyms and words in caps automatically with a <span> tag to format them via CSS.
Examples:
I live in the <span class="smcp">USA</span>.
My <span class="smcp">IP</span>-address is 0.0.0.0.
Do a Regex replace:
([A-Z][A-Z]+)
to
<span class="smcp">\1</span>

Parsing HTML Table using Regex

I am trying to extract the contents of the table using Regex.
I have removed most of the tags from the table, i am stuck with <br> , <a href >, <img > & <b> How to remove them ??
for <b> tag i tried this Regex
\s*<b[^>]*>\s*
(?<value>.*?)
\s* </b>\s*
it worked for some lines and some its giving the out put as
<b class="saadirheader">Email:</b>
Can anyone help me removing these tags
<br> , <a href >, <img > and <b>
Full Tags :-
<img src="Newrecord_files/spacer.gif" alt="" border="0" height="1" width="5">
<a href="mailto:first.last#email.org">
Thanking you,
Naveen HS
Use the following Regex:
(?:<br|<a href|<img|<b)(?:.(?!>))*.>
This Regex will match all the tags you mentioned above, and if there are more tags you forgot to mention just add a "|" sign with the tag you want to add, and insert it into the first parentheses.