<strong>result:</strong> {{#Regex.IsMatch value "(blob|master|test)"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}} {{#Regex.IsMatch value "/d+/"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}} {{#Regex.IsMatch value "ari[^n]"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}}
IgnoreCase
By default, regular expressions are matched against strings case-sensitively:
Context
{ "lower": "abc", "upper": "ABC" }
Usage
<strong>result:</strong> {{#Regex.IsMatch lower "abc"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}} {{#Regex.IsMatch upper "abc"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}}
Returns
<strong>result:</strong> <strong>True</strong> <strong>False</strong>
If you specify IgnoreCase, both input strings (abc and ABC) will be matched by the pattern abc:
<strong>result:</strong> {{#Regex.IsMatch upper "abc" "i"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}}
Returns
<strong>result:</strong> <strong>True</strong>
It's especially handy to use the IgnoreCase flag when using character classes: [a-zA-Z]
can then be shortened to [a-z]
. If you need to do a case-insensitive match, specifying this flag helps you write clearer, shorter, and more readable patterns.
Multiline
The Multiline flag changes the meaning of the special characters ^
and $
. Usually, they match at the beginning ^
and the end $
of the entire string. With Multiline applied, they match at the beginning or end of any line of the input string.
Here's how you could use Multiline to check whether some multi-line string (e.g. from a text file) contains a line that only consists of digits:
Context
Usage
<strong>result:</strong> {{#Regex.IsMatch input "^\d+$"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}} {{#Regex.IsMatch input "^\d+$" "m"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}}
Returns
<strong>result:</strong> <strong>False</strong> <strong>True</strong>
Singleline
Singleline changes the meaning of the dot (.
), which matches every character except \n
. With the Singleline flag set, the dot will match every character.
Sometimes, you'll see people use a pattern like [\d\D]
to mean "any character". Such a pattern is a tautology, that is, it's universally true — every character will either be or not be a digit. It has the same behavior as the dot with Singleline specified.
Context
Usage
<strong>result:</strong> {{#Regex.IsMatch input ".123"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}} {{#Regex.IsMatch input ".123" "s"}} <strong>True</strong> {{else}} <strong>False</strong> {{/Regex.IsMatch}}
Returns
<strong>result:</strong> <strong>False</strong> <strong>True</strong>
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4