in reply to Re: Re: A regex that does this, but not that?
in thread A regex that does this, but not that?
I spent quite a bit of time trying to craft my example carefully, so that if there was a regex solution to return the result I specified, I'd have my answer.
But the problem is that you left it at the example. I could have given you a couple of regexes that solved your example, but would probably have failed to do what you wanted on the second example you tried.
pg got it perfectly.Then you and he got lucky. If he came up with a different regexp that solved your one example, but that would do something else on other sentences, he would have wasted time formulating a useless answer. However, is it really true that pg's answer got it right? Your requirements say:
I want to delete any words that start with "t", end with "t", but do not contain any other "t"s within, except for the word "test".and pg's regex is:
Now, to me that regex just deletes strings starting with a t, and ending with the next t, with the exception of the word "test". So, let's try it on another example:s/(t.*?t)/($1 ne "test") ? "" : $1/ge;
Now, that might be exactly what you had in mind, but it doesn't suit the requirements.$_ = "this is the wristwatch"; s/(t.*?t)/($1 ne "test") ? "" : $1/ge; print; __END__ he wrisch
Abigail
|
|---|