in reply to Re: Match Optional Groups with 1 Required Group
in thread Match Optional Groups with 1 Required Group

This is great. I should have put in the post that there can be an unlimited number of titles, as long as there is one. I'm trying to modify it to allow that:
print "$_: ", m[^\w+(?:\.\w+)?$] ? "matched\n" : "failed\n" for qw[ one one.two one.two.three four.five.six.seven one. one-two + ];

Replies are listed 'Best First'.
Re^3: Match Optional Groups with 1 Required Group
by BrowserUk (Patriarch) on Feb 04, 2014 at 00:52 UTC

    ? is zero or one. You need *, which is 0 or more.:

    print "$_: ", m[^\w+(?:\.\w+)*$] ? "matched\n" : "failed\n" for qw[ one one.two one.two.three four.five.six.seven one. one-tw +o ];; one: matched one.two: matched one.two.three: matched four.five.six.seven: matched one.: failed one-two: failed
    Each title needs at least one character as well.

    + means 1 or more, so that's covered by \w+


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.