tags:

views:

74

answers:

3

Using Regex.

I have this to find the words that end with those letters:

\S+[abc]\b

But I need all the words that has these letters in any position but not in the end.

+6  A: 

the ^ character is regex for not (when used in a character group) so a slight modification to your regex will produce : \S+[^abc]\b : mach one or more non space characters and then any character besides a,b or c whose located at the word boundary

Alon
A small addition is necessary to this statement (added part in bold): “the ^ character is regex for _not_ (when used **as the first character** in a character group)”.`[^a]` and `[a^]` have different meanings. You probably knew that already, right? ;-)
Geert
+3  A: 

If [abc] must be somewhere in the word (except the end), you need this:

\S*[abc]\S*[^abc]\b

If [abc] doesn't need to be anywhere, Alon's solution is enough:

\S+[^abc]\b
Wim
A: 

a ^ to signify NOT a, b or c should work:

\S+[^abc]\b

xzqx
Nope the `\b` takes care of that (word boundary), `$` would be the end of input -- yours wouldn't match words in the middle of the string.
Wim
You're assuming that 'the end' means end of line ($), not 'end of word' (\b), as stated in the OP.
Forgotten Semicolon
Thx, figured that out as soon as I hit submit :(
xzqx