\b and accented letters\b et les lettres accentuées

The accents page showed how you can overcome the limitations of \w by using \p{L} instead, which does include accented letters. \b has no such way out: it stays defined by \w whether or not the u flag is on, and there is no Unicode property to put in its place.

The consequence is concrete, and easier to see than to explain. Figure 1figure 1 shows one sentence twice, with the word boundaries a reader sees above and the ones \b sees below. Since “é” and the other accented letters are not word characters for \b, three things happen:

  • An accented letter at the start or end of a word removes the boundary on that side, whether it touches a space (“thé”, “à”) or punctuation (the apostrophe in “l’été”, the comma after it): between two characters that are not word characters, \b sees no boundary.
  • An accented letter inside a word puts a boundary on each side of it, where there is none (“très”, “hôtel”, the “t” of “été”).
  • Words without accents (“un”, “chaud”) are delimited correctly.
The sentence “L'été, un thé très chaud à l'hôtel.” written twice, with a vertical line at each word boundary. In the first line, for a reader, every word is framed by two lines. In the second, for \b, “à” has no lines at all, the lines between the apostrophe and “été”, after “été” and after “thé” are missing, and extra lines cut “été”, “thé”, “très” and “hôtel” on either side of their accented letters.
Figure 1. The same sentence cut into words by a reader, then by \b.

A search for a whole word shows it most directly. Between two \b, a word without accents is found as intended, but a word ending in “é” is not, and its letters are found at the start of a longer word instead (the examples are French words):

ExpressionTextMatch
/\bthym\b/“du thym,”“thym”
/\bthé\b/“un thé,”none: no boundary between “é” and the comma
/\bthé\b/“la théorie”“thé”, at the start of “théorie”: there is a boundary between “é” and “o”
ExerciseExercice 8 not startedà faire solvedréussi keep tryingà retravailler
Expression: /\bcafé\b/
Test text (French): Un café, deux cafés et la cafétéria.
Which matches will be found?
Regex : /\bcafé\b/
Texte de test : Un café, deux cafés et la cafétéria.
Quelles correspondances seront trouvées ?
Show the solutionVoir la solution
Answer: c), the exact opposite of what was intended. To \b, "é" is not a word character. After "café", the comma is not one either: no boundary, so the word on its own is not found. In "cafés" and "cafétéria", the letter after "é" is a word character: there is a boundary in the middle of the word, and the expression finds "café" there.
Réponse : c), l'inverse exact de ce qu'on voulait. Pour \b, « é » n'est pas un caractère de mot. Après « café », la virgule n'en est pas un non plus : pas de limite, donc le mot seul n'est pas trouvé. Dans « cafés » et « cafétéria », la lettre qui suit « é » est un caractère de mot : il y a une limite au milieu du mot, et la regex y trouve « café ».
ExerciseExercice 9 · three-letter words: where \b gets it wrongmots de 3 lettres : où \b se trompe advancedavancé not startedà faire solvedréussi keep tryingà retravailler
Try to find the words of exactly three letters with \b and \p{L}, then compare the matches with what you expected: which ones are missing, and why? The test text stays French, because the lesson is what \b does to accented letters.
Essayez de trouver les mots d'exactement 3 lettres avec \b et \p{L}, puis comparez les correspondances à ce que vous attendiez : lesquels manquent, et pourquoi ?
Test textTexte de test
Il a été très fier. Son thé est là. Elle dit que non. Le mot 'car' aussi.
Il a été très fier. Son thé est là. Elle dit que non. Le mot 'car' aussi.
Expected matches:Correspondances attendues : trè Son est dit que non mot car
Expected matches:Correspondances attendues : trè Son est dit que non mot car
//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 24 September 2026

La page sur les accents a montré comment contourner les limites de \w en utilisant \p{L}, qui inclut les lettres accentuées. Le \b, lui, n’a pas d’échappatoire : il reste défini par \w, que le drapeau u soit actif ou non, et il n’existe aucune propriété Unicode pour le remplacer.

La conséquence est concrète, et elle se voit mieux qu’elle ne s’explique. La Figure 1figure 1 montre deux fois la même phrase, avec les limites de mot que voit un lecteur en haut et celles que voit \b en bas. Comme « é » et les autres lettres accentuées ne sont pas des caractères de mot pour \b, trois choses se produisent :

  • Une lettre accentuée au début ou à la fin d’un mot efface la limite de ce côté, qu’elle touche une espace (« thé », « à ») ou une ponctuation (l’apostrophe de « l’été », la virgule qui le suit) : entre deux caractères qui ne sont pas des caractères de mot, \b ne voit pas de limite.
  • Une lettre accentuée au milieu d’un mot place une limite de chaque côté, là où il n’y en a pas (« très », « hôtel », le « t » d’« été »).
  • Les mots sans accent (« un », « chaud ») sont délimités correctement.
La phrase « L'été, un thé très chaud à l'hôtel. » écrite deux fois, avec un trait vertical à chaque limite de mot. Dans la première ligne, pour un lecteur, chaque mot est encadré de deux traits. Dans la seconde, pour \b, « à » n'a aucun trait, les traits entre l'apostrophe et « été », après « été » et après « thé » manquent, et des traits en trop coupent « été », « thé », « très » et « hôtel » de part et d'autre de leurs lettres accentuées.
Figure 1. La même phrase découpée en mots par un lecteur, puis par \b.

La recherche d’un mot entier le montre le plus directement. Entre deux \b, un mot sans accent est trouvé comme prévu, mais un mot qui finit par « é » ne l’est pas, et ses lettres sont trouvées au début d’un mot plus long à la place :

ExpressionTexteCorrespondance
/\bthym\b/« du thym, »« thym »
/\bthé\b/« un thé, »aucune : pas de limite entre « é » et la virgule
/\bthé\b/« la théorie »« thé », au début de « théorie » : il y a une limite entre « é » et « o »
ExerciseExercice 8 not startedà faire solvedréussi keep tryingà retravailler
Expression: /\bcafé\b/
Test text (French): Un café, deux cafés et la cafétéria.
Which matches will be found?
Regex : /\bcafé\b/
Texte de test : Un café, deux cafés et la cafétéria.
Quelles correspondances seront trouvées ?
Show the solutionVoir la solution
Answer: c), the exact opposite of what was intended. To \b, "é" is not a word character. After "café", the comma is not one either: no boundary, so the word on its own is not found. In "cafés" and "cafétéria", the letter after "é" is a word character: there is a boundary in the middle of the word, and the expression finds "café" there.
Réponse : c), l'inverse exact de ce qu'on voulait. Pour \b, « é » n'est pas un caractère de mot. Après « café », la virgule n'en est pas un non plus : pas de limite, donc le mot seul n'est pas trouvé. Dans « cafés » et « cafétéria », la lettre qui suit « é » est un caractère de mot : il y a une limite au milieu du mot, et la regex y trouve « café ».
ExerciseExercice 9 · three-letter words: where \b gets it wrongmots de 3 lettres : où \b se trompe advancedavancé not startedà faire solvedréussi keep tryingà retravailler
Try to find the words of exactly three letters with \b and \p{L}, then compare the matches with what you expected: which ones are missing, and why? The test text stays French, because the lesson is what \b does to accented letters.
Essayez de trouver les mots d'exactement 3 lettres avec \b et \p{L}, puis comparez les correspondances à ce que vous attendiez : lesquels manquent, et pourquoi ?
Test textTexte de test
Il a été très fier. Son thé est là. Elle dit que non. Le mot 'car' aussi.
Il a été très fier. Son thé est là. Elle dit que non. Le mot 'car' aussi.
Expected matches:Correspondances attendues : trè Son est dit que non mot car
Expected matches:Correspondances attendues : trè Son est dit que non mot car
//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 24 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 :