http://qs321.pair.com?node_id=1211982


in reply to Looking for a regular expression for the following pattern.

Well, if the three alternatives are a bit tricky to reconcile, why not simply use three regexes and perhaps an if statement?
  • Comment on Re: Looking for a regular expression for the following pattern.

Replies are listed 'Best First'.
Re^2: Looking for a regular expression for the following pattern.
by AnomalousMonk (Bishop) on Mar 29, 2018 at 14:58 UTC

    No number of regexes and/or if-clauses will reconcile a requirement statement that doesn't state what is required.


    Give a man a fish:  <%-{-{-{-<

      The first two requirements sound like the same thing: /([:alnum:]+[_]+/. But the third requirement is a subset of the first, consuming the alnum sequence with no need for underscore. Two regexes joined by || logical-or would do it. However, it just might be as simple as replacing the last + in the above regex with * to indicate "zero or more" underscores. The pattern now looks for one-or-more alnum characters followed by zero-or-more underscores.

        So  'a_________'  '%%a_____%%'  '123456789_' would be strings skooma would want to match? That wasn't my (limited) understanding after reading the OP.

        c:\@Work\Perl\monks>perl -wMstrict -le "for my $s (qw(a_________ %%a_____%% 123456789_)) { print qq{'$s' matches} if $s =~ /[[:alnum:]]+[_]+/; } " 'a_________' matches '%%a_____%%' matches '123456789_' matches

        Update 1: And what about the  { } curlies?

        Update 2: And please use code tags when you post. Please see Writeup Formatting Tips and Markup in the Monastery.


        Give a man a fish:  <%-{-{-{-<