D'un tutoriel sur les expressions régulières - Caractères littéraux et caractères spéciaux :
Comme nous voulons faire plus que simplement rechercher des morceaux de texte littéraux, nous devons réserver certains caractères pour un usage spécial. Il y a au moins 12 caractères avec des significations spéciales :
la barre oblique inverse \, la chevron ^, le signe dollar $, le point ou la période ., la barre verticale ou le symbole pipe |, le point d'interrogation ?, l'astérisque ou l'étoile *, le signe plus +, la parenthèse ouvrante (, la parenthèse fermante ), la croche ouvrante [, et l'accolade ouvrante {, Ces caractères spéciaux sont souvent appelés « métacaractères ». La plupart d'entre eux sont des erreurs lorsqu'ils sont utilisés seuls.
Si vous voulez utiliser l'un de ces caractères comme littéral dans une expression régulière, vous devez les échapper avec une barre oblique inverse. Si vous voulez correspondre à 1+1=2, l'expression régulière correcte est 1\+1=2. Sinon, le signe plus a une signification spéciale.
Et dans PT, nous avons souvent besoin du \ dans une expression régulière, car il est si fondamental pour les usfms. Donc pour rechercher \p dans une expression régulière, vous tapez \\p.
(Il est utile d'apprendre à propos de l'échappement, car même dans cet outil de forum, certains caractères ne s'afficheront pas, à moins que vous ne les échappiez ou que vous n'utilisiez la fonctionnalité « texte préformaté » via l'icône </>.)
From a Regex Tutorial - Literal Characters and Special Characters:
Because we want to do more than simply search for literal pieces of text, we need to reserve certain characters for special use. There are at least 12 characters with special meanings:
the backslash \, the caret ^, the dollar sign $, the period or dot ., the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing parenthesis ), the opening square bracket [, and the opening curly brace {, These special characters are often called “metacharacters”. Most of them are errors when used alone.
If you want to use any of these characters as a literal in a regex, you need to escape them with a backslash. If you want to match 1+1=2, the correct regex is 1\+1=2. Otherwise, the plus sign has a special meaning.
And in PT, we often need the \ in a regex, because it is so fundamental for usfms. So to search for \p in a regex, you type \\p.
(It is useful to learn about escaping, as even in this forum-tool, certain characters will not render, unless you either escape them or use the “preformatted text” feature via the </> icon.)
Traduit automatiquement depuis English