In a list of words, what regular expression will find all five-letter
words that begin with "b" and do not end with the same last two
characters?
Here's a regular expression that will find all five-letter words that
begin with "b" and do end with the same last two characters:
$ egrep -i '^b..(.)\1$' /usr/share/dict/words
Bragg
Brett
Britt
bless
bliss
bluff
brass
And here's a way to get those words that don't end in the same letters
using a pipeline:
$ join -v 1 <(egrep -i '^b....$' /usr/share/dict/words | sort) <(egrep
-i '^b..(.)\1$' /usr/share/dict/words | sort) | wc -l
469
$ wc -l <(egrep -i '^b....$' /usr/share/dict/words | sort) <(egrep -i
'^b..(.)\1$' /usr/share/dict/words | sort)
476 /dev/fd/63
7 /dev/fd/62
But is there a way to do this in a single regular expression?
Trying to negate the backreference does not work:
$ egrep -i '^b..(.)[^\1]$' /usr/share/dict/words | wc -l
476
Perhaps I want to use a lookaround?
BTW, here's a nice tutorial on regular expressions:
http://www.regular-expressions.info/brackets.html
Regards,
- Robert
--~--~---------~--~----~------------~-------~--~----~
Central West End Linux Users Group (via Google Groups)
Main page: http://www.cwelug.org
To post: [email protected]
To subscribe: [email protected]
To unsubscribe: [email protected]
More options: http://groups.google.com/group/cwelug
-~----------~----~----~----~------~----~------~--~---