2010-05-06 4 views
1

Je veux découvrir mauvaise orthographe « foobar » dans la phrase:Comment créer une expression régulière correspondant à un mot mal orthographié avec la sensibilité à la casse d'origine?

« Ceci est un « foobar » exemple où je doit correspondre à différentes orthographes fooBar tels que: foobar, Foobar ou même foobar mais pas foobarS »

Dans cette phrase, je voudrais correspondre des mots (dans l'ordre): fooBar, foobar FOOBAR, Foobar et non: FooBar (orthographe correcte), foobarS (pas le même mot)

Est existe-t-il une solution existante utilisant Perl Regular Expression? Ceci est destiné à être utilisé avec grep -P

Merci

Répondre

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

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

+0

Pas assez générique, voir réponse acceptée, merci quand même pour votre aide! –

1
(?<=^|\W)(?!FooBar)(?i)foobar(?=\W|$) 
Questions connexes