Re:Show HN: Transductive regular expressions for text editing
by johnnymellor on Friday February 07, 2025 @04:47PM
(#42977874)
If I understand correctly the following ttre expression does what you're asking for:
":'(':(\\')|[^"'])*":'
Re:Show HN: Transductive regular expressions for text editing
by layer8 on Friday February 07, 2025 @07:53PM
(#42979262)
Good point, I didn't think of that solution.
Re:Show HN: Transductive regular expressions for text editing
by tomashubelbauer on Saturday February 08, 2025 @07:31AM
(#42982490)
So this is how it feels to read a regex when you don't know how to regex.
Re:Show HN: Transductive regular expressions for text editing
by c0nstantine on Saturday February 08, 2025 @09:58AM
(#42983330)
Thank you for doing my work! :)
Re:Show HN: Transductive regular expressions for text editing
by c0nstantine on Saturday February 08, 2025 @09:57AM
(#42983325)
Hi,
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.
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.