in reply to regular expression to match specific members of a bus_name

Please use <code> tags for your string patterns, it is currently very difficult to figure out exactly what you need.

A shoot in the dark which, even if it may not be exactly what you need, might still provide you some help::

my $regex = qr/\w{3}_[tr]x_[pn]\d/;

Replies are listed 'Best First'.
Re^2: regular expression to match specific members of a bus_name
by boleary (Scribe) on Feb 12, 2016 at 12:29 UTC

    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

      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.