Try to explain myself.
foo|bar is foo or bar. if it is grouped by (foo|bar), the matched $1 will be set to "foo" or "bar".
In this case ... it is not "non capturing grouping" (?foo|bar), because it is zero width look ahead assertion '(?='. Zero width look ahead assertion works like place holder and it does not eat up pos($expr) in matching.
$ is the end of line... as far as I know.
Well, it says look ahead for "end of line" or MARK and match against them as 'place holder'. I think I understand this!
#!/usr/bin/perl
use strict;
use warnings;
my $RefLine = "(a) This is first line(once all 4 was one line). (b) Th
+is is second line; (
print "original -----\n";
print "$RefLine\n";
print "original -----\n\n";
print "\n## without 'end of line or' condtion. last line fails\n";
while( $RefLine =~ /(\([a-z]\).*?)(?=\([a-z]\))/g ){
my $p=pos $RefLine;
print "$-[0], $p,matched=$&\n";
print "---\n";
}
print "\n## without lookahead assertion... \n";
while( $RefLine =~ /(\([a-z]\).*?)($|\([a-z]\))/g ){
my $p=pos $RefLine;
print "$-[0], $p,matched=$&\n";
print "---\n";
}
print "\n## with 'end of line or' condtion and zero width place holder
+\n";
while( $RefLine =~ /(\([a-z]\).*?)(?=$|\([a-z]\))/g ){
my $p=pos $RefLine;
print "$-[0], $p,matched=$&\n";
print "---\n";
}
Thank you very much JavaFan.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
|
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
|
|