Outils d'utilisateurs

Outils du Site


expressions_regulieres_3

Différences

Cette page vous donne les différences entre la révision choisie et la version actuelle de la page.

Lien vers cette vue

expressions_regulieres_3 [2015/06/17 00:37]
gbdivers
expressions_regulieres_3 [2019/01/30 21:56] (Version actuelle)
alavida [Réutiliser un groupe de capture]
Ligne 2: Ligne 2:
 ^ [[expressions_regulieres_2|Chapitre précédent]] ^ [[programmez_avec_le_langage_c|Sommaire principal]] ^ [[validation_motifs|Chapitre suivant]] ^ ^ [[expressions_regulieres_2|Chapitre précédent]] ^ [[programmez_avec_le_langage_c|Sommaire principal]] ^ [[validation_motifs|Chapitre suivant]] ^
  
-====== Les expressions régulières 3 ======+====== [Aller plus loin] Les expressions régulières 3 ======
  
 ===== Les groupes de capture ===== ===== Les groupes de capture =====
Ligne 57: Ligne 57:
 ==== Réutiliser un groupe de capture ==== ==== Réutiliser un groupe de capture ====
  
-Les chaînes identifiées par un groupe de capture peut être réutilisées dans le motif. Chaque groupe est identifié par un numéro, dans l'ordre de leur déclaration. Pour réutiliser une chaîne, il faut indiquer le numéro de groupe précédé d'une barre oblique inversée : <html>\1</html>, <html>\2</html>, <html>\3</html>, etc.+Les chaînes identifiées par un groupe de capture peuvent être réutilisées dans le motif. Chaque groupe est identifié par un numéro, dans l'ordre de leur déclaration. Pour réutiliser une chaîne, il faut indiquer le numéro de groupe précédé d'une barre oblique inversée : <html>\1</html>, <html>\2</html>, <html>\3</html>, etc.
  
 Par exemple, pour écrire un motif qui permet d'identifier n'importe quelle chaîne commençant et terminant par le même caractère, on pourra écrire le motif suivant : Par exemple, pour écrire un motif qui permet d'identifier n'importe quelle chaîne commençant et terminant par le même caractère, on pourra écrire le motif suivant :
Ligne 74: Ligne 74:
 { {
     std::regex const pattern { R"((.).*\1)" };     std::regex const pattern { R"((.).*\1)" };
-    std::cout << "'(.).*\1' match with '': " << std::boolalpha << +    std::cout << "'(.).*\\1' match with '': " << std::boolalpha << 
         std::regex_match("", pattern) << std::endl;         std::regex_match("", pattern) << std::endl;
    
-    std::cout << "'(.).*\1' match with 'abc': " << std::boolalpha << +    std::cout << "'(.).*\\1' match with 'abc': " << std::boolalpha << 
         std::regex_match("abc", pattern) << std::endl;         std::regex_match("abc", pattern) << std::endl;
    
-    std::cout << "'(.).*\1' match with 'aba': " << std::boolalpha << +    std::cout << "'(.).*\\1' match with 'aba': " << std::boolalpha << 
         std::regex_match("aba", pattern) << std::endl;         std::regex_match("aba", pattern) << std::endl;
    
-    std::cout << "'(.).*\1' match with 'abcdefa': " << std::boolalpha << +    std::cout << "'(.).*\\1' match with 'abcdefa': " << std::boolalpha << 
         std::regex_match("abcdefa", pattern) << std::endl;         std::regex_match("abcdefa", pattern) << std::endl;
 } }
Ligne 91: Ligne 91:
  
 <code> <code>
-'(.).*' match with '': false +'(.).*\1' match with '': false 
-'(.).*' match with 'abc': false +'(.).*\1' match with 'abc': false 
-'(.).*' match with 'aba': true +'(.).*\1' match with 'aba': true 
-'(.).*' match with 'abcdefa': true+'(.).*\1' match with 'abcdefa': true
 </code> </code>
  
Ligne 107: Ligne 107:
 ^ [[expressions_regulieres_2|Chapitre précédent]] ^ [[programmez_avec_le_langage_c|Sommaire principal]] ^ [[validation_motifs|Chapitre suivant]] ^ ^ [[expressions_regulieres_2|Chapitre précédent]] ^ [[programmez_avec_le_langage_c|Sommaire principal]] ^ [[validation_motifs|Chapitre suivant]] ^
  
-{{tag> Cours C++}} 
expressions_regulieres_3.1434494270.txt.gz · Dernière modification: 2015/06/17 00:37 par gbdivers