Thread: Regex examples
View Single Post
Old 03-18-2025, 01:25 PM   #775
Haudek
Member
Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.Haudek knows the difference between a duck.
 
Posts: 24
Karma: 111614
Join Date: Mar 2025
Location: Poland
Device: Kindle Voyage
Why?

What is its inconsistency?

Code:
<p><a(?: class="backlink")? href="(.+?)" id="(.+?)">([0-9]{1,4})</a>(?:\s)*(.+?)</p>
Note: This group that starts with ?: is not included in the group count, so whether the class will be or not - it should be OK.

Replace:
Code:
<p><a href="\1" id="\2">\3</a>\4</p>
Since in pure Sigil replacing finding (\s)*(.+?) does not remove spaces, use the "Pavulon" function (works in beta version):

Code:
def replace(match, number, file_name, metadata, data):
	if match:
		return "<p><a href=\"" + match.group(1) + "\" id=\"" + match.group(2) + "\">" + match.group(3) + "</a>" + match.group(4) + "</p>"
I don't quite understand what you're trying to achieve, but I hope this helps.
Haudek is offline   Reply With Quote