raybies has asked for the wisdom of the Perl Monks concerning the following question:

Can anyone tell me where I can find additional information and background on the newer regular expression formats? Particularly I see a lot of examples of help being provided with the liberal useage of the ? question mark in the expressions. I always thought ? was for making 0 or 1 of something, or for marking a quantifier as "nongreedy", but I am not familiar with these other uses. Also is the use of $1, $2... being obsoleted styllistically for this new ? thing?

Replies are listed 'Best First'.
Re: more info about regex updates
by ikegami (Patriarch) on Oct 20, 2010 at 19:32 UTC
Re: more info about regex updates
by Anonymous Monk on Oct 20, 2010 at 17:50 UTC
    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: more info about regex updates
by halfcountplus (Hermit) on Oct 20, 2010 at 19:01 UTC
      named capture buffers, like (?<NAME>pattern) and then $+{NAME} instead of $1
        Oh yay, something new & unknown! Will correct post.
Re: more info about regex updates
by aquarium (Curate) on Oct 20, 2010 at 22:15 UTC
    using the question mark as a quantity qualifier following a character or expression denotes 0 or 1 of those. perl has extensions to the standard regular expressions on systems with sed/awk/grep etc. quite a few of those extensions in perl regex start with a question mark inside brackets. non-greedy matching is with *? quantifier, nothing to do with the previous construct. sometimes you have to be careful with the non-greedy match, as it can also match the zero-width nothingness before the next match, if the next match can eat up the prior characters. the \1 \2 \3 etc match replacements are part of original (unix utilities) regular expression syntax, and are being phased out in perl, in favor of $1 $2 $3 etc. this is because the legacy syntax is only maximum 9 match replacements, i.e. \1 thru \9.
    all of these things are departures (extensions) to original (unix) regular expression syntax, and have been with us since perl 5.6 or 5.8. most of the extensions are typically not necessary in a lot of typical day to day work, and hence not widely known/used. it's pretty nice though to come from a unix background to learn perl, and find out that 99% of standard regex syntax applies. a good understanding of even the standard regular expression syntax is a good asset to have.
    the hardest line to type correctly is: stty erase ^H