Regex: Difference between revisions

154 bytes added ,  6 years ago
Line 4:
{{UC}}
 
== Metacharacters Defined || Metacharacter Examples==
MChar || Definition || Pattern || Sample Matches
^ Start of a string. || ^abc || abc, abcdefg, abc123, ...
$ End of a string. || abc$ || abc, endsinabc, 123abc, ...
. Any character (except \n newline) || a.c || abc, aac, acc, adc, aec, ...
| Alternation.
{...} Explicit quantifier notation.
[...] Explicit set of characters to match.
(...) Logical grouping of part of an expression.
* 0 or more of previous expression.
+ 1 or more of previous expression.
? 0 or 1 of previous expression; also forces minimal matching when an expression might match several strings within a search string.
\ Preceding one of the above, it makes it a literal instead of a special character. Preceding a special matching character, see below.
 
{|
| Metacharacters Defined || Metacharacter Examples
|-
| MChar || Definition || Pattern || Sample Matches
|-
| ^ || Start of a string. || ^abc || abc, abcdefg, abc123, ...
|-
| $ || End of a string. || abc$ || abc, endsinabc, 123abc, ...
|-
| . || Any character (except \n newline) || a.c || abc, aac, acc, adc, aec, ...
|-
| | || Alternation. || bill|ted || ted, bill
|-
| {...} || Explicit quantifier notation. || ab{2}c || abbc
|-
| [...] || Explicit set of characters to match. || a[bB]c || abc, aBc
|-
| (...) || Logical grouping of part of an expression. (abc){2} abcabc
|-
| * || 0 or more of previous expression. ab*c ac, abc, abbc, abbbc, ...
|-
| + || 1 or more of previous expression. ab+c abc, abbc, abbbc, ...
|-
| ? || 0 or 1 of previous expression; also forces minimal matching when an expression might match several strings within a search string. ab?c ac, abc
|-
| \ || Preceding one of the above, it makes it a literal instead of a special character. Preceding a special matching character, see below. a\sc a c
|}
 
== Character Escapes ==
 
Escaped Char || Description
 
ordinary characters || Characters other than . $ ^ { [ ( | ) ] } * + ? \ match themselves.
 
bill|ted ted, bill
ab{2}c abbc
a[bB]c abc, aBc
(abc){2} abcabc
ab*c ac, abc, abbc, abbbc, ...
ab+c abc, abbc, abbbc, ...
ab?c ac, abc
a\sc a c
 
 
 
Character Escapes
Escaped Char Description
ordinary characters Characters other than . $ ^ { [ ( | ) ] } * + ? \ match themselves.
\a Matches a bell (alarm) \u0007.
\b Matches a backspace \u0008 if in a []; otherwise matches a word boundary (between \w and \W characters).
Line 52:
 
 
== Character Classes ==
Char Class || Description
. Matches any character except \n. If modified by the Singleline option, a period character matches any character. For more information, see Regular Expression Options.
[aeiou] Matches any single character included in the specified set of characters.