Thread: Regex examples
View Single Post
Old 02-24-2022, 10:12 AM   #700
BillPearl
Junior Member
BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.BillPearl ought to be getting tired of karma fortunes by now.
 
Posts: 7
Karma: 591908
Join Date: Jun 2011
Device: Kindle
Find missing quote marks

Perhaps this may help you on your way.
Recently had to find missing first " of a pair. Finally came up with this:

Find strings with a missing first quote
... calibre3">((?:\\"|[^"])*")</p>
^^^^^--------tags ------^^^ bracket string

Search: ...calibre3">([")(?: (?= (\\?))\2.)*?\1</p> -between tags (no space after ?: ) ?

Replace: "\1 <-- (There's a space after the '1') -adds quote to front end of \1 (the captured text)

Did not work in all cases but this got the rest of the mis-matched pairs.
3">((?:\\"|[^"])*")[. , ?] -between tag and punctuation mark(s)

Quote:
Originally Posted by meme View Post
I'd like to see if I can collect Regular Expressions (PCRE format as introduced in Sigil 0.5.0) used for common or difficult issues, and maybe add them to the FAQ, etc. Partly so I can have a list to refer to when needed, but also to collect a lot of what's probably already been mentioned in this forum. And maybe to find out if there isn't a way to do a replacement that's needed.

For instance, is there a regex to do other types of replacement but only inside body tags?

Is there one only for the actual text - words not part of a tag name or attribute? Words that are only aprt of a tag name or attribute?

If you have any suggestions for the above cases, or any other useful Regex expressions please post them.
BillPearl is offline   Reply With Quote