
srhadden
Novice
Dec 20, 2011, 5:03 PM
Post #1 of 3
(2382 views)
|
|
Trying to extract a block of text from a string
|
Can't Post
|
|
Hi all, I have a string that is like this: " line1 line2 BEGIN BLOCK: stuff END BLOCK: line 3 line 4 " 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. Thanks
|