The pattern has one capturing subpattern, meaning -- with the
default flag for preg_match_all (PREG_PATTERN_O RDER), which
applies in this case as no flag was explicitly specified -- that
the $words array contains two further arrays: one array containing
full pattern matches, and another array containing the capturing
subpattern matches.
But because the U modifier (PCRE_UNGREEDY) is set, both arrays
will have exactly the same contents; that is, they'll both contain
values of one or more word characters followed by a single comma,
period, space, or question mark. That seems redundant to me.
I wonder what this pattern is supposed to accomplish.
On Mon, 10 Nov 2003 17:16:47 +0000, kaptain kernel <nospam@nospam. gov> wrote:
[color=blue]
>can anyone translate this into plain english?
>
>preg_match_all ("/(\w+[,. ?])+/U", $text, $words);[/color]
/U isn't a Perl regex modifier, manual for PCRE says it makes matches
non-greedy by default though.
For the rest, YAPE::Regex::Ex plain (a useful Perl module) comes up with:
(after appending '?' to all the quantifiers to make them non-greedy)
The regular expression:
(?-imsx:(\w+?[,. ?])+?)
matches as follows:
NODE EXPLANATION
----------------------------------------------------------------------
(?-imsx: group, but do not capture (case-sensitive)
(with ^ and $ matching normally) (with . not
matching \n) (matching whitespace and #
normally):
----------------------------------------------------------------------
( group and capture to \1 (1 or more times
(matching the least amount possible)):
----------------------------------------------------------------------
\w+? word characters (a-z, A-Z, 0-9, _) (1 or
more times (matching the least amount
possible))
----------------------------------------------------------------------
[,. ?] any character of: ',', '.', ' ', '?'
----------------------------------------------------------------------
)+? end of \1 (NOTE: because you're using a
quantifier on this capture, only the LAST
repetition of the captured pattern will be
stored in \1)
----------------------------------------------------------------------
) end of grouping
----------------------------------------------------------------------
Comment