
paxxus
New User
Oct 28, 2012, 5:58 AM
Post #1 of 6
(35417 views)
|
Multiline matching problem
|
Can't Post
|
|
Hello, I'm progressively matching through a string containing many lines and I want to skip lines containing white-space or line-comments; I'm multi-line matching here so white-space includes \n. The following perl program shows how I achieved this:
$s = <<END; // Hello // World xxx END $s =~ m,\G((//.*)?\s*)*,mgc; print ">", $s, "<\n"; print ">", substr( $s, pos( $s ) ), "<\n"; Here $s is my string and as expected the position is at the 'xxx' after the regexp has eaten through the empty lines and comments. The output of the program is:
> // Hello // World xxx < >xxx < If however I change the regexp to:
$s =~ m,\G(\s*|//.*)*,mgc; Then only the first empty line is eaten and the position is now at the first line-comment, which is not what I want. My problem is that I can't explain why the second version of the regexp doesn't work for me (as you might have guessed this was actually my first failed attempt). Can anyone help me understand this?
(This post was edited by paxxus on Oct 28, 2012, 6:01 AM)
|