Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Looking for a cleaner regex

by Eily (Monsignor)
on Dec 08, 2017 at 11:28 UTC ( [id://1205165]=note: print w/replies, xml ) Need Help??


in reply to Looking for a cleaner regex

I see some simplifications:

/e(?<!ste)/ means find a e and put the cursor right after it, then read the three letters before the cursor (e included) and check that this is not "ste". This is simply "a e not following st", so /(?<!st)e/ (only slightly shorter, but that's several chars overall)

/is(?<!ste)/ isn't very useful, if you put the match cursor right behind "is", the previous three letters obviously can't be "ste".

(?=PATTERN) makes perl check what's next without moving the match cursor. $ already check that what's next is the end of the string or of a line without moving the cursor. So (?=$) and $ mean the same thing.

Replies are listed 'Best First'.
Re^2: Looking for a cleaner regex
by k-man (Novice) on Dec 08, 2017 at 11:39 UTC

    Thanks for the info. The is/ste/ thing was a mistake... Can you give the alternative example to (?=$) because I was having trouble without it.

      If I want to find a string ending in foo or bar or baz, I just match against /(foo|bar|baz)$/ rather than repeat the EOL test in the regex. If that doesn't solve it for you perhaps using the techniques described in How to ask better questions using Test::More and sample data will help me and others understand where your problem lies.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2024-04-24 18:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found