Shorthand classes: \d, \w, \sClasses abrégées : \d, \w, \s

Some ranges come up so often that they have an abbreviation:

ShorthandEquivalentMeaning
\d[0-9]a digit
\w[a-zA-Z0-9_]a “word” character
\s[ \t\n\r] (among others)whitespace
\D[^0-9]anything but a digit
\W[^a-zA-Z0-9_]anything but a word character
\S[^ \t\n\r]anything but whitespace

The lowercase/uppercase pairing is a general principle, and it will come back: the lowercase names a set, the uppercase its complement.

ExerciseExercice 13 · the phone number, shortenedtéléphone, version abrégée basicbasique not startedà faire solvedréussi keep tryingà retravailler
Find the phone numbers (3-3-4 digits, any separator) using the shorthand classes.
Trouvez les numéros de téléphone (3-3-4 chiffres, séparateur quelconque) en utilisant les classes abrégées.
Test textTexte de test
Call me at 514-555-1234 or at 438.555.6789 for more. Code: 12-34. Date: 2024-01-15. My number is 5145551234 with no separators.
Appelez-moi au 514-555-1234 ou au 438.555.6789 pour plus d'infos. Code: 12-34. Date: 2024-01-15. Mon numéro est 5145551234 sans tirets.
Expected matches:Correspondances attendues : 514-555-1234 438.555.6789
Expected matches:Correspondances attendues : 514-555-1234 438.555.6789
//gmu
ExerciseExercice 14 · plausible times HH:MMheures plausibles HH:MM intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the times in HH:MM format while excluding the impossible values in the text (such as 99:45 or 23:78).
Trouvez les heures au format HH:MM en excluant les valeurs impossibles présentes dans le texte (comme 99:45 ou 23:78).
Test textTexte de test
Meeting at 14:30 or 09:15. Impossible values: 99:45, 23:78, 35:12, 18h00. Wrong format: 9:01, 12:5. Arriving around 08:00 or 23:59.
Rendez-vous à 14:30 ou 09:15. Heures invalides: 99:45, 23:78, 35:12, 18h00. Format incorrect: 9:01, 12:5. Arrivée vers 08:00 ou 23:59.
Expected matches:Correspondances attendues : 14:30 09:15 08:00 23:59
Expected matches:Correspondances attendues : 14:30 09:15 08:00 23:59
//gmu
ExerciseExercice 15 · postal codes with the shorthandscodes postaux avec les abrégés intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the postal codes in valid Canadian format (H3T 1J4, for example), using \d for the digits.
Trouvez les codes postaux au format canadien valide (ex. : H3T 1J4), en utilisant \d pour les chiffres.
Test textTexte de test
Addresses: H3T 1J4, G1K 7P4 and J5R 3B2. Invalid codes: H3T1J4, h3t 1j4, H3T-1J4, H3T 1j4, 3HT 1J4.
Adresses: H3T 1J4, G1K 7P4, et J5R 3B2. Codes invalides: H3T1J4, h3t 1j4, H3T-1J4, H3T 1j4, 3HT 1J4.
Expected matches:Correspondances attendues : H3T␣1J4 G1K␣7P4 J5R␣3B2 ␣ space · ⇥ tab · ⏎ line break · ◆ empty match␣ espace · ⇥ tabulation · ⏎ retour à la ligne · ◆ correspondance vide
Expected matches:Correspondances attendues : H3T␣1J4 G1K␣7P4 J5R␣3B2 ␣ space · ⇥ tab · ⏎ line break · ◆ empty match␣ espace · ⇥ tabulation · ⏎ retour à la ligne · ◆ correspondance vide
//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 14 September 2026

Certaines plages reviennent si souvent qu’elles ont leur abréviation :

AbrégéÉquivalentSignification
\d[0-9]un chiffre
\w[a-zA-Z0-9_]un caractère « de mot »
\s[ \t\n\r] (entre autres)un blanc
\D[^0-9]tout sauf un chiffre
\W[^a-zA-Z0-9_]tout sauf un caractère de mot
\S[^ \t\n\r]tout sauf un blanc

Le duo minuscule/majuscule est un principe général, et il reviendra : la minuscule désigne un ensemble, la majuscule son complément.

ExerciseExercice 13 · the phone number, shortenedtéléphone, version abrégée basicbasique not startedà faire solvedréussi keep tryingà retravailler
Find the phone numbers (3-3-4 digits, any separator) using the shorthand classes.
Trouvez les numéros de téléphone (3-3-4 chiffres, séparateur quelconque) en utilisant les classes abrégées.
Test textTexte de test
Call me at 514-555-1234 or at 438.555.6789 for more. Code: 12-34. Date: 2024-01-15. My number is 5145551234 with no separators.
Appelez-moi au 514-555-1234 ou au 438.555.6789 pour plus d'infos. Code: 12-34. Date: 2024-01-15. Mon numéro est 5145551234 sans tirets.
Expected matches:Correspondances attendues : 514-555-1234 438.555.6789
Expected matches:Correspondances attendues : 514-555-1234 438.555.6789
//gmu
ExerciseExercice 14 · plausible times HH:MMheures plausibles HH:MM intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the times in HH:MM format while excluding the impossible values in the text (such as 99:45 or 23:78).
Trouvez les heures au format HH:MM en excluant les valeurs impossibles présentes dans le texte (comme 99:45 ou 23:78).
Test textTexte de test
Meeting at 14:30 or 09:15. Impossible values: 99:45, 23:78, 35:12, 18h00. Wrong format: 9:01, 12:5. Arriving around 08:00 or 23:59.
Rendez-vous à 14:30 ou 09:15. Heures invalides: 99:45, 23:78, 35:12, 18h00. Format incorrect: 9:01, 12:5. Arrivée vers 08:00 ou 23:59.
Expected matches:Correspondances attendues : 14:30 09:15 08:00 23:59
Expected matches:Correspondances attendues : 14:30 09:15 08:00 23:59
//gmu
ExerciseExercice 15 · postal codes with the shorthandscodes postaux avec les abrégés intermediateintermédiaire not startedà faire solvedréussi keep tryingà retravailler
Find the postal codes in valid Canadian format (H3T 1J4, for example), using \d for the digits.
Trouvez les codes postaux au format canadien valide (ex. : H3T 1J4), en utilisant \d pour les chiffres.
Test textTexte de test
Addresses: H3T 1J4, G1K 7P4 and J5R 3B2. Invalid codes: H3T1J4, h3t 1j4, H3T-1J4, H3T 1j4, 3HT 1J4.
Adresses: H3T 1J4, G1K 7P4, et J5R 3B2. Codes invalides: H3T1J4, h3t 1j4, H3T-1J4, H3T 1j4, 3HT 1J4.
Expected matches:Correspondances attendues : H3T␣1J4 G1K␣7P4 J5R␣3B2 ␣ space · ⇥ tab · ⏎ line break · ◆ empty match␣ espace · ⇥ tabulation · ⏎ retour à la ligne · ◆ correspondance vide
Expected matches:Correspondances attendues : H3T␣1J4 G1K␣7P4 J5R␣3B2 ␣ space · ⇥ tab · ⏎ line break · ◆ empty match␣ espace · ⇥ tabulation · ⏎ retour à la ligne · ◆ correspondance vide
//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 14 septembre 2026

Sources

Sources

Spotted an error? Une erreur ?

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

ayla.rigouts.terryn@umontreal.ca

Please mention the page: Mentionnez la page :