On Thu, 22 Nov 2001 12:24:11 +0100 (MET), Louis Pouzin wrote: >On Wed, 21 Nov 2001 09:45:19 -0500, Ronald J Kimball wrote: > >>Conjunction in a regex has higher precedence than alternation, so your regex is >parsed as: > >>/(?:^Date:\s+Mon)|(?:Tue)|(?:Wed)|(?:Thu)|(?:Fri)|(?:Sat)|(?:Sun,\s+(\d\d?))/ > >>You need to put parens around the matching of the days. > >Thank you, I get it. Except that now I don't see why there is '?:' in front of each >alternation in the expanded regex. Is this an instance of the '? ... :' operator ?
Most definitely not. These are regexes, which is an entirely different language inside perl. So there are different syntax rules. (?:RE) (with RE any regex) is the same as (RE) except that it doesn't do any capturing. For example: /(a|b)(c+)/ will try to match an a or a b, followed by a sequence of c's, and stuff the results in $1 and $2 respectively. /(?:a|b)(c+)/ matches the same thing, except it skips the first result ("a" or "b") and puts the chain of c's into $1. The leading question mark was taken as a marker because because of its nature, a grouping/capturing opening paren followed by a question mark is otherwise illegal syntax. So there's no clash with any conceivable regexes. As an extra, but I'm not exactly sure when this was introduced (maybe it doesn't work for the old MacPerl?), you can put modifiers, which are traditionally attached at the end of the // or s///, can be put between the "?" and the ":". Thus: /a(?i:b)c/ can match a lower case "a", any case "b", and lower case "c". So it's the /i modifier applied only to the group in the middle. Example: $_= "abcAbcabCaBc"; while(/a(?i:b)c/g) { print "Match: \"$`<$&>$'\"\n"; } Result: Match: "<abc>AbcabCaBc" Match: "abcAbcabC<aBc>" So it matches the "abc" and "aBc" groups at the start and at the end of the string, but not the "Abc" or the "abC" in the middle. You can insert several modifiers at once, but I'm pretty sure the /g (and /c) won't work. -- Bart.