0

I've come up with the following regular expression:

\[release(\s+(?<release_type>.*))?\]\n+(?<release_notes>.*)

The idea is to parse a commit message for several params:

[release minor]

Hello world

- asd
- zxc

Matching should result release_type = 'minor', release_notes = 'Hello world\n….

I'm trying to use perl due to old regex engines in macOS.

I've tried:

perl -e 'print "$+{release_notes}" while /\[release(\s+(?<release_type>.*))?\]\n+(?<release_notes>.*)/gs;' msg.txt

But for some reason, this expression doesn't work as expected.

In fact, even the simpler

perl -ne 'print "$+{release_notes}" while /\n(?<release_notes>.*)/gs;' msg.txt 

fails.

This

perl -ne 'print "$+{release_notes}" while /(?<release_notes>.*)/gs;' msg.txt 

succeeds and just returns the whole input.

I'm probably missing something simple here, but not sure what it is.

0

This answer game me a solution: adding -0777 to the command fixes the problem.

To quote:

It still needs that even as the -0777 unsets the input record separator, so the file is read at once; see https://stackoverflow.com/questions/37582501/why-use-the-p-n-in-slurp-mode-in-perl-one-liner/37583183#37583183

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.