in reply to Match Optional Groups with 1 Required Group

print "$_: ", m[^\w+(?:\.\w+){0,2}$] ? 'matched' : 'failed' for qw[ one one.two one.two.three one. one-two ];; one: matched one.two: matched one.two.three: matched one.: failed one-two: failed

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.

Replies are listed 'Best First'.
Re^2: Match Optional Groups with 1 Required Group
by rem45acp (Novice) on Feb 04, 2014 at 00:48 UTC
    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 + ];

      ? 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.
Re^2: Match Optional Groups with 1 Required Group
by rem45acp (Novice) on Feb 04, 2014 at 00:49 UTC
    Each title needs at least one character as well.
      Ah sweet.