View Single Post
Old 08-14-2024, 09:59 AM   #1
lindlind
Junior Member
lindlind began at the beginning.
 
Posts: 6
Karma: 10
Join Date: Mar 2024
Device: none
Replace group in Regex function mode

I have the following string:

Code:
<span class="line">Come here, he says.<span aria-label="11" class="page-normal" id="d5e1496" role="doc-pagebreak" title="11" epub:type="pagebreak"></span></span><br />
If I do a search and replace in Regex mode like this:

Search:
Code:
<span([^>]*"pagebreak"> ?)</span>
Replace:
Code:
<xxspan\1</xxspan>
The result is:

Code:
<span class="line">Come here, he says.<xxspan aria-label="11" class="page-normal" id="d5e1496" role="doc-pagebreak" title="11" epub:type="pagebreak"></xxspan></span><br />

However, if I add the following in a Regex-function:

Code:
return regex.sub('<span([^>]*"pagebreak"> ?)</span>', '<xxspan\1</xxspan>', match.group())
The result is this:

Code:
<span class="line">Come here, he says.<xxspan</xxspan></span><br />
What am I doing wrong here?
lindlind is offline   Reply With Quote