|
|
|
|
|
by c0nstantine
495 days ago
|
|
Fair point. The most explicit example if you need to change something in context. For example if we need to change 'y' to 'Y' only if it occurs between x and y you would do something like this in python. pattern = r'(x)y(z)' replacement = r'\1Y\2' result = re.sub(pattern, replacement, text) I would like to replace it with 'xy:Yz' pattern: result = re.trre('xy:Yz', text) If you need your x, z to be more complicated patterns or even regex themselves it can be more handy using this approach. |
|
I guess I'm still struggling to see how it's simpler overall.
Most of the examples on your page don't involve groups at all, e.g.:
That already seems a lot more complicated than just: I don't need to use groups that often in regex replacements, and when I do I'm already trying to do something complicated, and it's not clear to me why the colon syntax is easier to write, easier to understand, or if it's as flexible.Not trying to criticize the project, just genuinely trying to understand the specific strengths and limitations of the proposed syntax. E.g. what if I want to turn xyz into zYx?