I need a Regex that will look at the last word in the string and eliminate it if it’s a word that I’ve selected. For instance, if I’m selecting the word “dog,” “This dog is a great dog” would return “This dog is a great.” I don’t want it to affect all the instances of that word, only if it happens to be at the very end of a string.
This is for a Yahoo Pipe that I’m setting up. Thanks in advance for your help.
-Mike
The regex
\bdog$matches only at the end of the string. If there can be whitespace after your keyword, try\bdog\s*$. If you want to allow other characters (except for alphanumerics) afterdog, for example punctuation, then use\bdog\W*$.\bis a word boundary anchor that makes sure that only an entire worddogis matched – not part of a word as inunderdog.\smatches whitespace.\wmatches an alphanumeric characters;\Wmatches anything that’s not an alnum.