This content describes Snap 11. For Snap 10, the equivalent page will be in Snap 10 help
Pattern: |
Matches |
Explanation |
|---|---|---|
abc |
abc |
If the pattern contains only text, then the data will match if it is the same as the pattern. |
. |
Any character |
If there is a dot in the pattern, then that character is matched against any character in the data. |
x+ |
1 or more x |
If we want a character to be repeated, we can put a + after it. |
|
Any word beginning with J |
This pattern is looking to match a word starting with a J. |
|
0 or more x |
This is similar to + in that we are looking for a repeated character, but will allow for the character before the * not to appear in the data. |
[ace] |
a or c or e |
A single character can be matched from a range of characters if the characters are placed in square brackets. |
|
A or B or C or D or E |
Matches any character within the range specified. |
[^abc] |
Any character except a or b or c |
Placing a ^ at the front of a set of characters forces a match of anything that is NOT in the set. |
\d |
Any digit 0-9 |
If you want to match a digit, you can use [0~9] or you can use the equivalent short-cut \d. |
\D |
Not Digit |
If you want to match anything except a digit |
\w |
Character or digit |
If you want to match a word character. Note that this accepts letters, numbers and the underscore. |
\W |
[^a~zA~Z0~9_] |
If you want to match anything except a word character. This is especially useful when you want to match punctuation, spaces and other symbols, but do not want a word character or digit to be matched. |
\s |
space |
used to match a pattern containing a space |
\S |
non-space |
This short-cut matches against everything except a space. |
\meta |
char itself |
There are times when you want to match for a dot or a backslash. However, these characters have special meanings in the pattern. You tell Snap that you want it to really look for a dot by putting a backslash in front of it. The same is true of * + and any other symbols. Similarly, if you want to look for a backslash you put a second backslash in front of it. |
Repetition expressions
Pattern: |
Matches |
Explanation |
|---|---|---|
x? |
0 or x |
If you have an optional character, place a ? after it. |
x{3} |
xxx |
You can say how many times something is repeated by putting the number of repeats in curly brackets after the character. |
x{2,5} |
xx or xxx or xxxx or xxxxx |
You can say how many times something is repeated and name the minimum and maximum number of times. |
x{2,} |
xx or xxx or xxxx with no maximum. |
You can say how many times something is repeated from a minimum number but not specify a maximum. |
|
See Also |