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

That matches "1" and "a\n". It doesn't match "a_".

  • Comment on Re^2: Looking for a regular expression for the following pattern.

Replies are listed 'Best First'.
Re^3: Looking for a regular expression for the following pattern.
by hdb (Monsignor) on Mar 29, 2018 at 13:33 UTC

    Next try...

    /^(([a-zA-Z0-9]{2,}_)*[a-zA-Z0-9]{2,})$/ && print "$_\n" for "1", "a\n", "aa\n", "a_", "aa", "aa_bb_cc_dd", "a1_11_1c_11", +"aaa", "aa_";

    Still matches a trailing newline. It does not match "aa_" on purpose as this is not a sequence of two or more alphanumeric characters separated by underscores which was my claim if not the original question.