in reply to Re: Re: combining RegEx
in thread combining RegEx

No, [ease] is the same as [aes] and means one character which may be one of 'a', 'e', or 's'. What you want is the string ease modified by the "match either one or zero times" qualifier '?'. Since '?' has high precedence, saying ease? means the string "eas" optionally followed by 'e'. To make the '?' apply to the whole string "ease", you enclose it in parentheses (ease)?.

Since parentheses have two functions (to affect precedence and to cause capture of a submatch (e.g. into $1)) and you often want to do the former but not the latter, there is a special form of parentheses that don't capture: (?: before and ) after. This odd way of extending regex syntax was chosen since (? regex was otherwise meaningless and illegal.

Does that help?

You can install modules YAPE::Regex and YAPE::Regex::Explain and say (for example) print YAPE::Regex::Explain->new("(ease)?")->explain() to get a verbose blow-by-blow description of what a particular regex does.

Replies are listed 'Best First'.
Re: Re: Re: Re: combining RegEx
by Anonymous Monk on Nov 04, 2003 at 18:44 UTC
    Very much...Thanks :)