tags:

views:

55

answers:

3

I want to discover wrong spelling of "FooBar" in sentence:

"This is a 'FooBar' example where I should match different spelling of fooBar such as: foobar, FOOBAR or even fOoBaR but not foobarS!"

In this sentence, I would like to match words (in order): fooBar, foobar, FOOBAR, fOoBaR and not: FooBar (correct spelling), foobarS (not the same word)

Is there an existing solution using Perl Regular Expression? This is intended to be used with grep -P

Thanks

+4  A: 
echo "$str" | grep -P '\b(?!FooBar)(?i:foobar)\b'
KennyTM
A: 

cat foobar.txt | grep -P '(?!FooBar)[fF][oO][oO][bB][aA][rR]'

Sjoerd
Not generic enough, see accepted answer, thanks anyway for your help!
Patrick Allaert
+1  A: 
(?<=^|\W)(?!FooBar)(?i)foobar(?=\W|$)
Superfilin