Thread: Regex examples
View Single Post
Old 10-07-2023, 07:33 AM   #747
Turtle91
A Hairy Wizard
Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.Turtle91 ought to be getting tired of karma fortunes by now.
 
Turtle91's Avatar
 
Posts: 3,361
Karma: 20212223
Join Date: Dec 2012
Location: Charleston, SC today
Device: iPhone 15/11/X/6/iPad 1,2,Air & Air Pro/Surface Pro/Kindle PW & Fire
‘Greediness’ refers to how much of the string to be searched gets matched.

If you say you want </h1>(.*)</p> it would capture EVERYTHING from the end of the </h1> to the LAST </p> in your file …. very greedy.

You can specify a minimal capture that would only capture up to the FIRST occurrence of </p>. There are a couple ways of doing that: clicking minimal match like KevinH mentioned, my favorite is to add a question mark to the capture group. </h1>(.*?)</p>

If you want a minimal capture of the first line (paragraph) after your heading you could try this:
Code:
Find: </h1>\s*<p.*?>(.*?)</p>
Replace: </h1>\n<h2>\1</h2>
That looks for the closing header tag followed by any amount of white space followed by an opening paragraph tag with anything in it (classes, styles, etc.) then it captures anything within that paragraph up to the first paragraph closing tag. It then replaces all of that with the closing header tag, and it inserts what it captured, using the \1, into a new heading (level 2) tag.
Turtle91 is offline   Reply With Quote