On Mon, 10 Nov 2003 17:16:47 +0000, kaptain kernel <no****@nospam.gov> wrote:
can anyone translate this into plain english?
preg_match_all("/(\w+[,. ?])+/U", $text, $words);
/U isn't a Perl regex modifier, manual for PCRE says it makes matches
non-greedy by default though.
For the rest, YAPE::Regex::Explain (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
----------------------------------------------------------------------
--
Andy Hassall (an**@andyh.co.uk) icq(5747695) (
http://www.andyh.co.uk)
Space: disk usage analysis tool (
http://www.andyhsoftware.co.uk/space)