in reply to regular expression

Hi

See this great collection for more infos on how to create regexes.

HTH, Rata

Update: better use /^[a-zA-Z]\)/ instead of  /^\w\)/ - thanks JohnGG

Replies are listed 'Best First'.
Re^2: regular expression
by johngg (Canon) on Jun 02, 2014 at 09:41 UTC
    /^\w+\)/ extracts a letter followed by a closing bracket

    \w also matches digits.

    $ perl -E 'say $1 if q{ab1d2f} =~ m{^(\w+)$};' ab1d2f $

    Cheers,

    JohnGG

Re^2: regular expression
by davido (Cardinal) on Jun 02, 2014 at 17:05 UTC

    Possibly even better than [a-zA-Z], which makes a limiting assumption about the alphabet being used, one could use \p{Alpha}, which accepts 102159 different code points, all of which may be considered part of the alphabet of some language somewhere at some time, and none of which include numeric digits.

    Instead of I+, how about using Regexp::Common's $RE{num}{roman} pattern, which will correctly match roman numerals, case insensitively. Here's the pattern it uses to do so:

    (?xi)(?=[MDCLXVI]) (?:M{0,3} (D?C{0,3}|CD|CM)? (L?X{0,3}|XL|XC)? (V?I{0,3}|IV|IX)?)

    Dave