4 ms·
I get that PEGs are more powerful than regexes, but it seems the example of componentizing is weak at best. I can do this very easily on the command line or in
by greggyb 8y ago
I get that PEGs are more powerful than regexes, but it seems the example of componentizing is weak at best.
I can do this very easily on the command line or in a .<shell>rc file:
ipv4component='[0-9]{1,3}'
ipv4="$ipv4component"'\.'"$ipv4component"'\.'"$ipv4component"'\.'"$ipv4component"
$ grep -E $ipv4 ...
I am bad at regex, so I'm sure the example is a poor definition, but the idea is there. I can make variables that hold components of a regex, and since a regex is just a string I can compose these via concatenation.
If I did this a lot, I could build a small helper script (or probably just a set of shell functions) to maintain a library file of regex components that I can use in the shell with grep.
- taeric 8y agoIt isn't that hard to build functions around a lot of this, either. Emacs has the wonderful macro "rx". https://www.emacswiki.org/emacs/rx https://www.emacswiki.org/emacs/rx