• BASH > les expressions régulières (regex)

      CARACTÈRES

      . n’importe quel caractère

      \b un espace

      \W alphanumérique

      \b\W+\b un mot complet

      \b(toto)\b le mot toto

      CHOIX

      | ou  → (toto|titi) toto ou titi

      [] choix de caractères → t[oi]tototo ou tito

      () → →

      POSITION

      ^ début

      $ fin

       

      RÉPÉTITIONS

      * 0 ou 1 ou plusieurs fois

      + au moins 1 fois

      {3} 3 fois exactement

      {3,} au moins 3 fois

      {3,5} entre 3 et 5 fois

       

      egrep "([0-9]{1,3})" → chiffre répété 1 à 3 fois → 7 ou 75 ou 854

      RÉCUPÉRER UNE OCCURRENCE

      Les occurrences limités par des parenthèse ( ), peuvent être rappelés par les symboles \

      (regex1)bla(regex2)\1 \2

      PARTICULARITÉS

      avec sed

      les caractères { , } , ( , ) , + , ? , | doivent être échappés pour être opérationnels.

       

      sed "s/[0-9]\{5,\}//g"

      sed "s/\(toto\)\+//g"

       

      EXEMPLES

      mots en doublons

      (\b\W+\b)\1\1

       

 

Aucun commentaire

 

Laissez un commentaire