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>
Related
Using <div dir=.*?> works fine to match <div dir="auto">.
However, why does <div dir=.*?><br \/> not match <div dir="auto"><br />?
Code: https://regex101.com/r/5pP38n/1
The regexp starts matching at the first <div dir= in the input. Then it looks for the next ><br \/> in the input. .*? will match everything between them, which is
"auto">Please š sir my youtube channel delete <div dir="auto"
You don't match <div dir="auto"><br /> because it's contained inside this match, and a regexp doesn't return overlapping matches.
If you don't want .*? to match across multiple tags, you can use [^>]* instead.
<div dir=[^>]*><br \/>
DEMO
So I have a unordered list that looks like:
<ul class='radio' id='input_16_5'>
<li>
<input name='input_5' type='radio' value='location_1' id='choice_16_5_0' />
<label for='choice_16_5_0' id='label_16_5_0'>Location 1</label></li>
<li>
<input name='input_5' type='radio' value='location_2' id='choice_16_5_1' />
<label for='choice_16_5_1' id='label_16_5_1'>Location 2</label></li>
<li>
<input name='input_5' type='radio' value='location_3' id='choice_16_5_2' />
<label for='choice_16_5_2' id='label_16_5_2'>Location 3</label></li>
</ul>
I would like to pass a value (ie. location_2) to a regular expression that will then capture the whole list item that it's a part of in order to remove it. So if I pass it location_2 it will match the to the (including) <li> and the </li> of the list item that it's in.
I can match up to the end of the list item with /location_3.+?(?=<li|<\/ul)/ but is there something I can do to match before and not capture other items?
This should get what you want
<li>(?:(?!<li>)[\S\s])+location_1[\S\s]+?<\/li>
Exaplanation
<li>: open li tag,
(?:(?!<li>)[\S\s])+: match for any characters including a newline and use negative look ahead to make sure that your highlight will not consume two or more <li> tags,
location_1: keyword that you use for highlight the whole <li> tag,
[\S\s]+?: any characters including a newline. (Here, thanks #Tensibai for your comment that make this regex be more simple with non-greedy)
<\/li> close li tag.
DEMO: https://regex101.com/r/cU4eC6/5
Additional information:
/<li>(?:(?!<li>).)+location_2.+?<\/li>/s
This regex is also work where you use modifier s to handle a newline instead of [\S\s]. (Thanks again to #Tensibai)
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
<a class='jdr' href='javascript:void(0);' onClick="return openDiv('jrtp');"></a>
<span class="jcn">
<a href="http://example.com/Ahmedabad/Aptech-N-Power-Hardware-Networking-<near>-Toll-Naka-Opp-Kakadia-Hospital-Below-Sankalp-Reataurant-Bapu-Nagar/079PXX79-XX79-110420173655-D4K6_QWhtZWRhYmFkIENDTkEgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET" title='Aptech N Power Hardware & Networking' >Aptech N Power Hardware & Networkin...</a>
</span>
<section class="jrat">
<a rel="nofollow" href="http://example.com/Ahmedabad/Aptech-N-Power-Hardware-Networking-<near>-Toll-Naka-Opp-Kakadia-Hospital-Below-Sankalp-Reataurant-Bapu-Nagar/079PXX79-XX79-110420173655-D4K6_QWhtZWRhYmFkIENDTkEgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET#rvw"><span class='s10'></span><span class='s10'></span><span class='s10'></span><span class='s10'></span><span class='s0'></span></a>
<a class="jrt" href="http://example.com/Ahmedabad/Aptech-N-Power-Hardware-Networking-<near>-Toll-Naka-Opp-Kakadia-Hospital-Below-Sankalp-Reataurant-Bapu-Nagar/079PXX79-XX79-110420173655-D4K6_QWhtZWRhYmFkIENDTkEgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET#rvw">2 ratings</a>
<span class="jrt"> |</span>
<a class="rate_this" onclick="_ct('ratethis','lspg');" href="http://example.com/Ahmedabad/Aptech-N-Power-Hardware-Networking-<near>-Toll-Naka-Opp-Kakadia-Hospital-Below-Sankalp-Reataurant-Bapu-Nagar/079PXX79-XX79-110420173655-D4K6_QWhtZWRhYmFkIENDTkEgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET/writereview">Rate this</a>
</section>
<section class="jcar">
<section class="jbc">
<a href="http://example.com/Ahmedabad/Aptech-N-Power-Hardware-Networking-<near>-Toll-Naka-Opp-Kakadia-Hospital-Below-Sankalp-Reataurant-Bapu-Nagar/079PXX79-XX79-110420173655-D4K6_QWhtZWRhYmFkIENDTkEgVHJhaW5pbmcgSW5zdGl0dXRlcw==_BZDET">
<img width="83" height="56" border="0" src="http://images.jdmagicbox.com/upload_test/ahmedabad/b4/079pxx79.xx79.110420172948.d4b4/logo/faf3f2409ed7993aaa70f848ab0bb6fb_t.jpg" class="Clogo" />
</a>
<!-- <span class="noLogo"></span> -->
<section class="jrcl">
<p>
**A/35, Lakhani Chamber, Toll Naka, Opp Kakadia Hospital, Below Sankalp Reataurant, Bapu Nagar, Ahmedabad - 380024** | View Map<br>
</p>
From the above XML data I want to extract the following---
A/35, Lakhani Chamber, Toll Naka, Opp Kakadia Hospital, Below Sankalp Reataurant, Bapu Nagar, Ahmedabad - 380024
I need help in creating a regular expression to find and remove all lines containing special characters.
I am using the following regex ----
/(\<.+?>)/g
Please help.Thanks
Try this
/(?<=\*{2})([^<>]*?)(?=\*{2})/g
it matches all content between the **.
I think you want to remove lines which are HTML tags, so try this:
/^<.*>\n/g
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.