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.