Dec 20, 2011, 5:03 PM
Post #1 of 3
Trying to extract a block of text from a string
I have a string that is like this:
I want to take such a string, and extract everything between and including the BEGIN BLOCK: and END BLOCK: words.
I am using this:
$str =~/(.*)BEGIN BLOCK:.*END BLOCK(.*)/s;
I had to use /s because I want .* to include newlines.
Then I put the pieces back together
$newstr = "$1$2";
Something isn't right though, I don't always get the stuff after my block. I always get $1, but not $2.
Hopefully I explained the basic problem and someone can suggest a better regex.