isha has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: Regular expression query
by FunkyMonk (Bishop) on Jul 30, 2007 at 07:55 UTC
    It's difficult to know what should and shouldn't match from your limited examples, especially as I see the opposite to your claim of which matches (even after fixing your typo):
    for ( 'A_TAG_HSSL_LBA_1', 'A_TAG_HSSL_LBAB_1' ) { if( ! /A_[A_Z0-9_]+/i) { print "$_ is not matching\n"; } else { print "$_ matches\n"; } }

    Produces:

    A_TAG_HSSL_LBA_1 matches A_TAG_HSSL_LBAB_1 is not matching

    I think the regexp is matching somewhere other than where you think it's matching. A_TAG_HSSL_LBA_1 is matched at A_1, not at the start.

    I suspect the regexp you're after is really

    /^ # start of string A_ # must start "A_" [A-Z0-9_]+ # at least one capital, digit or underscore $ # end of string /ix # allow spaces and comments inside regexp # and ignore case

    Or, /^A_[A-z0-9_]+$/i in short. But, since you're ignoring case (which I just noticed), [A-Z0-9_] are just "word" characters, so your regexp reduces to: /^A_\w+$/i

    Of course, this is all guesswork, so it could well be all wrong.

Re: Regular expression query
by Samy_rio (Vicar) on Jul 30, 2007 at 06:43 UTC

    Hi isha, I am not clear with your question. The problem may be in variable name $t1, which should be $t and inside character class range should be [A-Z], since you are using underscore seprately in the character class.

    if($t1 !~ /A_[A_Z0-9_]+/i) it should be if($t !~ /A_[A-Z0-9_]+/i) Output: ------- $CD = 'A_TAG_HSSL_LBA_1'; #matches $CD = 'A_TAG_HSSL_LBAB_1'; #not matches

    Also look into this How do I post a question effectively?

    Regards,
    Velusamy R.


    eval"print uc\"\\c$_\""for split'','j)@,/6%@0%2,`e@3!-9v2)/@|6%,53!-9@2~j';