Special characters in regexes and how to escape them

08 Th9 2020
0 Comments

Regex – Regular Expression

Cradle provides support for regular expressions, regular expressions are a means to find variable text in places such as:

  • Queries
  • Find dialogs
  • Category recognition strings
  • Category value validations

For instance, regular expressions (regexes) can be used in queries to find all items in which any frame, or a specific frame, or any of a list of frames, contains text matching the regular expression that you are searching for. For example, if you wanted to find all items containing sequences of capital letters followed by numbers, then the regular expression would be:

[A-Z]+[0-9]+

Special Characters

Some characters have special meanings within regexes these characters are:

CharDescriptionMeaning
\BackslashUsed to escape a special character
^CaretBeginning of a string
$Dollar signEnd of a string
.Period or dotMatches any single character
|Vertical bar or pipe symbolMatches previous OR next character/group
?Question markMatch zero or one of the previous
*Asterisk or starMatch zero, one or more of the previous
+Plus signMatch one or more of the previous
( )Opening and closing parenthesisGroup characters
[ ]Opening and closing square bracketMatches a range of characters
{ }Opening and closing curly braceMatches a specified number of occurrences of the previous

Examples

Finished\? matches “Finished?
^http matches strings that begin with http
[^0-9] matches any character not 0-9
ing$ matches “exciting” but not “ingenious
gr.y matches “gray“, “grey
Red|Yellow matches “Red” or “Yellow
colou?r matches colour and color
Ah? matches “Al” or “Ah
Ah* matches “Ahhhhh” or “A
Ah+ matches “Ah” or “Ahhh” but not “A
[cbf]ar matches “car“, “bar“, or “far
[a-zA-Z] matches ascii letters a-z (uppercase and lower case)

Using Special Characters as Literal Characters

If you want to use any of these as literal characters you can escape special characters with \ to give them their literal character meaning.

Example

If you want to match 1+2=3, you need to use a backslash (\) to escape the + as this character has a special meaning (Match one or more of the previous).
To match the 1+2=3 as one string you would need to use the regex 1\+2=3

For further information on using regexes in Cradle see our online help.

Trả lời

Lọc
Wishlist
Account
FB Chat
This site uses cookies to offer you a better browsing experience. By browsing this website, you agree to our use of cookies.