4 ms·
This doesn’t seem sufficient as soon as you want to perform some kind of structural substitution, for example doing the equivalent of s/"([^"]*)"/'$1'/. If it c
by layer8 2y ago
This doesn’t seem sufficient as soon as you want to perform some kind of structural substitution, for example doing the equivalent of s/"([^"]*)"/'$1'/. If it could do that and also somehow be able to replace any of the [^"] that match ['] by \', that would seem more useful.
More generally speaking, since regular expressions effectively define a parse tree on their matches, being able to perform more general transformations of those trees would be useful.
- johnnymellor 2y agoIf I understand correctly the following ttre expression does what you're asking for: ":'(':(\\')|[^"'])*":'
- layer8 2y agoGood point, I didn't think of that solution.
- tomashubelbauer 2y agoSo this is how it feels to read a regex when you don't know how to regex.
- c0nstantine 2y agoThank you for doing my work! :)
- c0nstantine 2y agoHi, If I understand it correctly you want to change something inside the "..." block and change the quotas to single '. It can be done by this expression: echo '"hello world" "hello again!"' | ./trre "\":'.+?:-\":'" '-' '-' So I substitute the text inside "" by symbol - using this expression ".+?:-" and simultaneously changing the surrounding quota. Question mark means non-greedy mode.