News for hackers. Stuff that matters.
Re:Pattern Matching Without Regex – Introducing the Rosie Pa... by greggyb on Wednesday November 14, 2018 @01:20PM (#18452268)
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.

Re:Pattern Matching Without Regex – Introducing the Rosie Pa... by taeric on Wednesday November 14, 2018 @01:45PM (#18452564)
It 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