De un tutorial de expresiones regulares - Caracteres literales y caracteres especiales:
Como queremos hacer más que simplemente buscar fragmentos literales de texto, necesitamos reservar ciertos caracteres para uso especial. Hay al menos 12 caracteres con significados especiales:
la barra invertida \, el acento circunflejo ^, el signo de dólar $, el punto o punto ., la barra vertical o símbolo de tubería |, el signo de interrogación ?, el asterisco o estrella *, el signo de más +, el paréntesis de apertura (, el paréntesis de cierre ), el corchete de apertura [, y la llave de apertura {, Estos caracteres especiales a menudo se llaman «metacaracteres». La mayoría de ellos son errores cuando se usan solos.
Si quiere usar cualquiera de estos caracteres como literal en una expresión regular, necesita escaparlos con una barra invertida . Si quiere coincidir 1+1=2, la expresión regular correcta es 1\+1=2. De lo contrario, el signo de más tiene un significado especial.
Y en PT, a menudo necesitamos la \ en una expresión regular, porque es tan fundamental para usfms. Por lo tanto, para buscar \p en una expresión regular, escribe \\p.
(Es útil aprender sobre el escape, ya que incluso en esta herramienta de foro, ciertos caracteres no se renderizarán, a menos que los escape o use la función de «texto preformateado» a través del icono </>.)
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.)
Traducción automática desde English Mostrar original