in reply to Re: regular expression to match specific members of a bus_name
in thread regular expression to match specific members of a bus_name

Sorry, I am trying to match a word segment with a specific number in it, but there can't be any extra digits following that number. I think I might have cleared that up when I updated the question

if I am looking for foo1 then:

foo1 should match but foo10 should not match

and foo1bar should match but foo10bar should not match

if I were looking for bar25 then:

bar2 would not match, bar25 would match , bar250 would not match

bar25foo would match and bar250foo would not match

Thanks for the help! I think the AnamolousMonk has my solution

  • Comment on Re^2: regular expression to match specific members of a bus_name

Replies are listed 'Best First'.
Re^3: regular expression to match specific members of a bus_name
by Laurent_R (Canon) on Feb 12, 2016 at 18:52 UTC
    Yes, it seems that you've figured it out by now, thanks to AnamolousMonk: the easiest way for achieving what you want is a negative look-ahead assertion:
    my $regex = qr/\w{3}_[tr]x_[pn]\d(?!\d)/;
    But even if you did not know about zero-width assertions, you could still have obtained more or less the same resukt with an alternation:
    my $regex = qr/\w{3}_[tr]x_[pn]\d(\D|$)/;
    which means: match everything to the required digit, followed by either a non-digit or the end of the string.

    TIMTOWTDI.