"The parentheses are used for the repeat factor. All my research on the internet indicates a multi-character pattern that needs to be repeated multiple times should be enclosed in parentheses. Is this not correct?"
Here's a test showing clustering and capturing. Both match as expected. Capturing also sets $1.
$ perl -Mstrict -Mwarnings -E '
my $re1 = qr{PV1\|1\|O\|(?:[^|]*\|){3}\|};
my $re2 = qr{PV1\|1\|O\|([^|]*\|){3}\|};
my $x = q{PV1|1|O|F3|F4|F5|F6|F7};
my $y = q{PV1|1|O|F3|F4|F5||F7};
say "------- Clustering -------";
say "Match in \$x" if $x =~ /$re1/;
say $1 if $1;
say "Match in \$y" if $y =~ /$re1/;
say $1 if $1;
say "------- Capturing -------";
say "Match in \$x" if $x =~ /$re2/;
say $1 if $1;
say "Match in \$y" if $y =~ /$re2/;
say $1 if $1;
'
------- Clustering -------
Match in $y
------- Capturing -------
Match in $y
F5|
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|