Groups: (...)Les groupes : (...)

A quantifier applies to the element in front of it: a character, a class… or a group. Parentheses create that group, and give the quantifier something bigger to count:

  • /(ha)+/ → “ha”, “haha”, “hahaha”…;
  • /(anti)?virus/ → “virus” or “antivirus”;
  • /(\d{3}-){2}/ → “three digits and a hyphen”, twice over.

The second example is the most useful in practice. Making one character optional with ? is common; making a whole portion of the pattern optional, a prefix, a decimal part, an area code, takes a group.

ExerciseExercice 9 · hahaahahaa advancedavancé not startedà faire solvedréussi keep tryingà retravailler
Find every variant of laughter: "ha", "haha", "haaa", "hahaa" and so on (but not "hihi" or "hoho").
Trouvez toutes les variantes de rire : « ha », « haha », « haaa », « hahaa », etc. (mais pas « hihi » ni « hoho »).
Test textTexte de test
ha haha haaa hahaa haaahaha hihi hoho
ha haha haaa hahaa haaahaha hihi hoho
Expected matches:Correspondances attendues : ha haha haaa hahaa haaahaha
Expected matches:Correspondances attendues : ha haha haaa hahaa haaahaha
//gmu
ExerciseExercice 10 · words with the re or ré prefixmots avec préfixe re ou ré intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the words starting with "re" or "ré". The test text stays French: the prefix takes an accent in one spelling and not in the other, which is the point of the exercise.
Trouvez les mots qui commencent par « re » ou « ré ».
Test textTexte de test
Je réécris ce texte, je le rererelis plusieurs fois. Il faut le réorganiser, le relire et y remédier, mais pas prendre, corriger, arrêter ni créer.
Je réécris ce texte, je le rererelis plusieurs fois. Il faut le réorganiser, le relire et y remédier, mais pas prendre, corriger, arrêter ni créer.
Expected matches:Correspondances attendues : réécris rererelis réorganiser relire remédier
Expected matches:Correspondances attendues : réécris rererelis réorganiser relire remédier
//gmu
ExerciseExercice 11 · phone numbers with a groupnuméros de téléphone avec un groupe intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the numbers in XXX-XXX-XXXX format using a repeated group instead of writing the same thing twice.
Trouvez les numéros au format XXX-XXX-XXXX en utilisant un groupe répété au lieu d'écrire deux fois la même chose.
Test textTexte de test
Call 514-123-4567 or 438-987-6543. My fax is 555-0000. Code: 123-45. Date: 2024-01-15.
Appelez le 514-123-4567 ou le 438-987-6543. Mon fax est 555-0000. Code: 123-45. Date: 2024-01-15.
Expected matches:Correspondances attendues : 514-123-4567 438-987-6543
Expected matches:Correspondances attendues : 514-123-4567 438-987-6543
//gmu
Written alternately in EN and FR, translation partly generated in both directions. Rédigé en alternance en EN et en FR, traduction en partie générée dans les deux sens. Updated 2026-08-27

Un quantificateur porte sur l’élément qui le précède : un caractère, une classe… ou un groupe. Les parenthèses créent ce groupe, et donnent au quantificateur quelque chose de plus gros à compter :

  • /(ha)+/ → « ha », « haha », « hahaha »… ;
  • /(anti)?virus/ → « virus » ou « antivirus » ;
  • /(\d{3}-){2}/ → deux fois de suite « trois chiffres et un tiret ».

Le deuxième exemple est le plus utile en pratique. Rendre un caractère optionnel avec ? est courant ; rendre optionnelle une portion entière du motif, un préfixe, une partie décimale, un indicatif régional, demande un groupe.

ExerciseExercice 9 · hahaahahaa advancedavancé not startedà faire solvedréussi keep tryingà retravailler
Find every variant of laughter: "ha", "haha", "haaa", "hahaa" and so on (but not "hihi" or "hoho").
Trouvez toutes les variantes de rire : « ha », « haha », « haaa », « hahaa », etc. (mais pas « hihi » ni « hoho »).
Test textTexte de test
ha haha haaa hahaa haaahaha hihi hoho
ha haha haaa hahaa haaahaha hihi hoho
Expected matches:Correspondances attendues : ha haha haaa hahaa haaahaha
Expected matches:Correspondances attendues : ha haha haaa hahaa haaahaha
//gmu
ExerciseExercice 10 · words with the re or ré prefixmots avec préfixe re ou ré intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the words starting with "re" or "ré". The test text stays French: the prefix takes an accent in one spelling and not in the other, which is the point of the exercise.
Trouvez les mots qui commencent par « re » ou « ré ».
Test textTexte de test
Je réécris ce texte, je le rererelis plusieurs fois. Il faut le réorganiser, le relire et y remédier, mais pas prendre, corriger, arrêter ni créer.
Je réécris ce texte, je le rererelis plusieurs fois. Il faut le réorganiser, le relire et y remédier, mais pas prendre, corriger, arrêter ni créer.
Expected matches:Correspondances attendues : réécris rererelis réorganiser relire remédier
Expected matches:Correspondances attendues : réécris rererelis réorganiser relire remédier
//gmu
ExerciseExercice 11 · phone numbers with a groupnuméros de téléphone avec un groupe intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the numbers in XXX-XXX-XXXX format using a repeated group instead of writing the same thing twice.
Trouvez les numéros au format XXX-XXX-XXXX en utilisant un groupe répété au lieu d'écrire deux fois la même chose.
Test textTexte de test
Call 514-123-4567 or 438-987-6543. My fax is 555-0000. Code: 123-45. Date: 2024-01-15.
Appelez le 514-123-4567 ou le 438-987-6543. Mon fax est 555-0000. Code: 123-45. Date: 2024-01-15.
Expected matches:Correspondances attendues : 514-123-4567 438-987-6543
Expected matches:Correspondances attendues : 514-123-4567 438-987-6543
//gmu
Written alternately in EN and FR, translation partly generated in both directions. Rédigé en alternance en EN et en FR, traduction en partie générée dans les deux sens. Mise à jour 2026-08-30

Sources

Sources

Spotted an error? Une erreur ?

Language, content, a broken link: tell me what you saw and I will fix it. Langue, contenu, lien brisé : dites-moi ce que vous avez vu et je corrige.

Sending opens your mail app with the report addressed to me. L'envoi ouvre votre application de courriel avec le signalement déjà adressé à moi.