Albeit the typical first reaction might be that of XKCD 927 [1] (I must confess it was mine, at least), I believe that the regular expressions territory could see some innovation. If told to pick just one feature from eggex, I'd choose the ability to parse statically! Right now, my modus operandi to work with regex is opening RegExr [2] without even thinking about it. I'd hope if the eggex syntax gets more traction, such useful tooling would appear around it too.
I wonder if eggex supports more advanced features such as positive/negative lookahead and lookbehind searches; I tend to use the positive ones a lot when setting new values to configuration files, with minimum repetition of the search terms (basically achieving no repetition at all in the substitution string):
# Replaces:
# my_fn(LIBNAME MyLib VERSION ANYTHING REQUIRED)
# With:
# my_fn(LIBNAME MyLib VERSION ^1.2.3 REQUIRED)
perl -i -pe \
's/my_fn\(LIBNAME MyLib VERSION \K.*(?= REQUIRED\))/^1.2.3/' \
MyFile.cmake
2 comments
[ 4.3 ms ] story [ 15.5 ms ] threadI wonder if eggex supports more advanced features such as positive/negative lookahead and lookbehind searches; I tend to use the positive ones a lot when setting new values to configuration files, with minimum repetition of the search terms (basically achieving no repetition at all in the substitution string):
[1]: https://xkcd.com/927/[2]: https://regexr.com/
Yes there is syntax reserved for backtracking constructs. It all starts with !! so you can audit it.
https://www.oilshell.org/release/0.8.7/doc/eggex.html#backtr...
So I think your example would be something like:
(since we translate only to ERE at the moment this isn't implemented, but space is reserved in the language)Not sure what \K is offhand. Oh that's to replace the whole thing?
Can you just use 2 groups, like this?
Then you replace it with '$1 ^1.2.3 $2' essentially.I forget if sed has submatches. I know it has the weird & for $0.
But if not then you can use eggex with perl -pie. You can use either the lookahead style (in theory), or the submatch style (already supported).
Let me know if that doesn't make sense... I think this is a good example to work through the APIs