📜 ⬆️ ⬇️

Regular expressions - character classes, construction of choice, metasequence

In J. Friedl's book “Regular expressions” there is a beautiful sign I want to give here.
Regular expressions provide ample opportunities for search and replace in any text. Using regular expressions you can flexibly and simply process text documents. One of the simplest uses of regular expressions is text search - many text editors have the ability to search for regular expression patterns . There are several types of metacharacters that perform different functions in regexp , let's briefly look at them: It should be noted that the rules that determine the composition of supported metacharacters (and their interpretation) are completely different inside and outside of character and excluding character classes.
Regex metacharacters
SymbolTitleInterpretation
Elements denoting a single character
.pointone any character
[…]character classany of the listed characters
[^…]inverted character classany character not listed in class
\screeningif the character is preceded by the escape prefix "\", then the character is interpreted as the corresponding literal
Quantifiers
?question markone copy is allowed
(none required)
*starany number of copies allowed
(none required)
+a plusone copy is required,
any number of copies allowed
{min, max}interval quantifier *“min” instances required, “max” results allowed
Positional metacharacters
^cover, circumflexposition at the beginning of the line
$dollarposition at the end of the line
\<word boundary *position at the beginning of the word
\>word boundary *position at the end of a word
Other metacharacters
|selection designany of the listed expressions
(…)round bracketsconstraint for choice construction, grouping for applying quantifiers, and saving text for backlinks
\1, \2, …back linktext that previously matched the first, second, etc. pairs of parentheses
* these features are not supported by all egrep versions

')

Source: https://habr.com/ru/post/55843/


All Articles