[pcre-dev] [Bug 2511] Feature Request: PCRE2_SUBSTITUTE, op…

Αρχική Σελίδα
Delete this message
Συντάκτης: admin
Ημερομηνία:  
Προς: pcre-dev
Αντικείμενο: [pcre-dev] [Bug 2511] Feature Request: PCRE2_SUBSTITUTE, option for getting *just* the replacement of a single match
https://bugs.exim.org/show_bug.cgi?id=2511

--- Comment #1 from Philip Hazel <ph10@???> ---
You can do this with the existing API:

* Call pcre2_substitute() in the usual way, supplying a match_data block, but
not setting PCRE2_SUBSTITUTE_GLOBAL (PCRE2_SUBSTITUTE_MATCHED optional).

* Afterwards, extract from the match data block the offsets of the start and
end of the match, call them M1 and M2.

* Calculate L = length-of-subject - M2

* Calculate M3 = length-of-result - L

Then the replacement string is the substring with offsets M1 to M3 in the
replacement.

Yes, this does do more work that is strictly necessary for what you want
(copying the pre-match and post-match strings into the replacement), but I
don't think this is very much, so I don't think it is worth implementing,
documenting, and maintaining a whole new API for what I suspect is a rather
rare requirement.

--
You are receiving this mail because:
You are on the CC list for the bug.