How can I match end-of-line multiple times in a regex without interpolation?

Posted by harschware on Stack Overflow See other posts from Stack Overflow or by harschware
Published on 2010-05-20T18:08:22Z Indexed on 2010/05/21 1:00 UTC
Read the original article Hit count: 293

Filed under:
|
|

Hi, if I have a input with new lines in it like:

[INFO]
xyz
[INFO]

How can I pull out the xyz part? I tried a pattern like /^\[INFO\]$(.*?)$\[INFO\]/ms, but perl gives me:

Use of uninitialized value $\ in regexp compilation at scripts\t.pl line 6.

I've been trying things to get interpolation to stop like using qr// but alas, no love.

EDIT: The key is that the end-of-line anchor is a dollar sign but at times it may be necessary to intersperse the end-of-line anchor through the pattern. If the pattern is interpolating then you might get problems such as uninitialized $\. For instance an acceptable solution here is /^\[INFO\]\s*^(.*?)\s*^\[INFO\]/ms but that does not solve the crux of the first problem. I've changed the anchors to be ^ so there is no interpolation going on, and with this input I'm free to do that. But what about when I really do want to reference EOL with $ in my pattern? How do I get the regex to compile?

© Stack Overflow or respective owner

Related posts about perl

Related posts about regex