Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

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

by boleary (Scribe)
on Feb 12, 2016 at 12:29 UTC ( [id://1155069]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1155069]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2024-04-19 04:18 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found