I want to insert a line break before and after a specific string in Notepad ++
to the glory
<hr />
<strong>Collect:</strong>
I want to achieve this
to the glory
<hr />
<strong>Collect:</strong>
can I do this in Notepad++ ?
You could find the horizontal rule and replace with the full match $0 and append a newline in front and after.
Find what:
^<hr />$
Replace with:
\n$0\n
Pattern demo
You can use a regex capturing group like this:
and then use find and replace.
Related
I need some help with Regular expression to Search and Replace in Sublime to do the following.
I have HTML-code with links like
href="http://www.example.com/test=123"
href="http://www.example.com/test=6546"
href="http://www.example.com/test=3214"
I want to replace them with empty links:
href=""
href=""
href=""
Please help me to create a Reg. ex. filter to match my case. I guess it would sound like "starts with Quote, following with http:// .... ends with Quote and has digitals and '=' sign", but I'm not very confident of how to write this in Reg. ex. way.
(?<=href=")[^"]*
Try this.Replace by empty string.
See demo.
https://regex101.com/r/sH8aR8/40
I'm still fairly green when it comes to regular expressions. What I am trying to achieve is :
Source:
<!-- Text --><b>Text</b>
Link
<div class="col"><h1>Nested Content</h1><p>More content</p>
</div>
<!-- END of Text -->
More text <!-- Another Tag Comment -->
Expected Capture :
$1 = Text
$2 = <b>Text</b>
Link
<div class="col"><h1>Nested Content</h1><p>More content</p>
</div>
$3 = END of Text
Current Regex :
/\<\!-*( *[A-Za-z]*) *-*\>([\s\S\t\r]*)\<\!-*( *[A-Za-z]*) *-*\>/igm
The issues are its too greedy it continues until the match in the source ending with :
$3 = Another Tag Comment
How do I go about refactoring my regex to end with the expected capture ?
<!--((?:(?!-->).)*)-->((?:(?!<!--)[\s\S])+)<!--((?:(?!-->).)*)-->
You can try this.See demo.
https://regex101.com/r/cA4wE0/17
You need to make the inner pattern [\s\S]* as non-greedy and also you need to add \s or space inside the last character class [A-Za-z]* . Add word boundaries \b, inorder to do an exact string match.
\<\!-* *([A-Za-z]*) *-*\>([\s\S]*?)<!-* *(\b[A-Za-z ]*\b) *-*\>
DEMO
In an Ant build file, is there a way to use a replaceregexp to find and replace two tags, and retain what's in between them? For example, to find all of these:
</a>1234abcdefg</P>
</a>123456789. </p>
</a> yop </p>
</a></p>
and replace
</a> and </p>
with
<#> and <##>
so that I have, respectively:
<#>1234abcdefg##
<#>123456789. <##>
<#> yop <##>
<#><##>
I can't replace the tags individually since they occur in other places, I just want the instances in which </a> is followed by </p>, in the same line, with either nothing or something in between them, and I want to keep what's in between them.
Try this:
<replaceregexp file="notTested.xml" match="(<)\/a(>.*?<)\/p(>)" replace="\1#\2##\3" byline="true" flags="g" />
as for, but it replaces what's between the tags with .* , i haven't seen .* in a replacement/substitution expression. probably it takes it as literals . and *.
as for </a>.*</p>, the > .* < will not work when you have multiple declerations of </a> and </p> on the same line... such as:
</a>1234abcdefg</P>abcde</a>123456789. </p> would be replaced as
<#>1234abcdefg</P>abcde</a>123456789. <##>
you need to use non greedy quantifier ?. See WiKi for the use of .*? vs .*.
Solution 1: You can try this
You store the match with parenthesis, and then replace it.
exp = new Regex(#"YourtagStartRegex(bodyRegex)YourtagClosingRegex");
str = exp.Replace(str, "$1");
Reference:Replace the start and end of a string ignoring the middle with regex, how?
Or
Solution 2:
Regex ignore middle part of capture
include_once($pathToRoot.'header.php');
echo('</div>');
assume you have variations on the above code across hundreds of files, how do you match against the first occurrence of
</div>
after
header.php'
?
In the find field:
(?s)(header\.php'.+?)</div>
In the replace (if you what to replace </div> with </test>):
$1</test>
I don't know that sublimetext2 but the regular expression would look like this:
/include_once\($pathToRoot.'header.php'\);(.*?)(<\/div>)/s
The first group would be the string between the include and the closing div and the second group would be the closing div itself.
In my HTML I have below tags:
<img src="../images/img.jpg" alt="sometext"/>
Using regex expression I want to remove alt=""
How would I write this?
Update
Its on movable type. I have to write it a like so:(textA is replaced by textB)
regex_replace="textA","textB"
Why don't you just find 'alt=""' and replace it with ' ' ?
On Movable Type try this:
regex_replace="/alt=""/",""
http://www.movabletype.org/documentation/developer/passing-multiple-parameters-into-a-tag-modifier.html
What regex you are asking for ? Straight away remove ..
$ sed 's/alt=""//'
<img src="../images/img.jpg" alt=""/>
<img src="../images/img.jpg" />
This does not requires a regex.
The following expression matches alt="sometext"
alt=".*?"
Note that if you used alt=".*" instead, and you had <img alt="sometext src="../images/img.jpg"> then you would match the whole string alt="sometext src="../images/img.jpg" (from alt=" to the last ").
The .* means: Match as much as you can.
The .*? means: Match as little as you can.
s/ alt="[^"]*"//
This regex_replace modifier should match any IMG tag with an alt attribute and capture everything preceding the alt attribute in group #1. The matched text is then replaced with the contents of group #1, effectively stripping off the alt attribute.
regex_replace='/(<img(?:\s+(?!alt\b)\w+="[^"]*")*)\s+alt="[^"]*"/g','$1'
Is that what you're looking for?