in reply to Hlelp regarding regex

check if the last but one letter from the first digit is always a "Y"

Assuming you mean "last but one letter after the first digit", this seems to work:

$re = qr[\d+\D+Y\D(\d|$)];; print '\\files\builds\data\M9998SBQCACSYD30401S' =~ $re ? 'yes' : 'no' +;; yes print '\\files\builds\data\M9998SBQCACSXD30401S' =~ $re ? 'yes' : 'no' +;; no

The regex says:

$re = qr[ \d+ # after the first (and any subsequent digits ) \D* # there should be some none digits Y # and a Y \D # followed by only one more non-digit (\d|$) # before another digit or end of string ]x;

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: Hlelp regarding regex
by Anonymous Monk on Jun 02, 2011 at 04:25 UTC

    Sorry forthe unclear spec...Hope the below is clear

    Spec:- After the last "\" $x should match the pattern Y(digit)(number).The reason is "$x" is given as an option by the user and we use the letter to distinguish the location of some files,we only want to process locations with letter Y.Can you please help?

    my $x = "\\\\files\\builds\\data\\M9998SBQCACSYD30401S";-->should matc +h my $x = "\\\\files\\builds\\data\\M9998SBQCACSAD30401S";-->Should not +match