No such thing as a small change | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
any words that start with "t", end with "t", but do not contain any other "t"s within
OK so that's \bt[^t]+t\b -- word-boundary, then a t, then one or more other characters not a t, then a t, then a word boundary. Apart from the abbreviation "tt" this should be fine. So "tent", "tesseract", "tot", "tort" and "test" itself will match this pattern. However, "testament" will fail it because of the "t" in the middle. Then you need a special case for "test" itself, which you can do with the /e modifier and the ternary operator, as in pg's example above. So something like this:
Where the regex means "Find words matching t, something-not-t, then t at the end. Replace them with nothing, unless they're the word test, in which case, replace them with themselves". You could replace the ternary thing with this more longwinded version if you liked:
In reply to Re: Re: Re: A regex that does this, but not that?
by Cody Pendant
|
|