Quick reference
Basics #
Pomsky | Explanation | Regex |
---|
"string" | String | string |
'string' | Raw string (no backslash escaping) | string |
'a' | 'b' | a OR b | a|b |
('a' | 'b') | Group (non-capturing) | (?:a|b) |
| Line comment |
|
. | any code point except \n | . |
Repetitions #
Pomsky | Explanation | Regex |
---|
'test'* | 0 or more | (?:test)* |
'test'+ | 1 or more | (?:test)+ |
'test'? | 0 or 1 | (?:test)? |
'test'{4,} | 4 or more times | (?:test){4,} |
'test'{4,7} | 4 to 7 times | (?:test){4,7} |
'test'+ lazy | Lazy (non-greedy) repetition | (?:test)+? |
Variables #
let x = 'foo' | 'bar';
x '-' x
Variables are replaced with their content in the produced regex:
(?:foo|bar)-(?:foo|bar)
Character sets #
Pomsky | Explanation | Regex |
---|
[···] | character set | [···] |
![···] | negated character set | [^···] |
[n t] | special characters (line feed, tab) | [\n\t] |
['a' 'd'] | an ‘a’ or ’d’ | [ad] |
['ad'] | an ‘a’ or ’d’ | [ad] |
['a'-'d'] | code points ‘a’ through ’d’ | [a-d] |
[U+45 U+FFEF] | code points U+0045 and U+FFEF | [\x45\uFFEF] |
Built-in character classes #
Pomsky | Explanation | Regex |
---|
[word] , [w] | any ‘word’ code point (letter, digit, or _ ) | \w |
[Latin] | any code point in the ‘Latin’ script | \p{Latin} |
[Letter] | any code point in the ‘Letter’ category | \p{Letter} |
[ascii_digit] | any ASCII digit | [0-9] |
[!word] | any code point except ‘word’ code points | \W |
See all shorthand character classes and all supported Unicode properties.
Anchors, boundaries, assertions #
These don’t match one or more characters, but a position in the string.
Pomsky | Explanation | Regex |
---|
^ | start of string | ^ |
$ | end of string | $ |
% | word boundary | \b |
!% | not a word boundary | \B |
< | start of a word | |
> | end of a word | |
(>> 'x') | lookahead assertion | (?=x) |
(<< 'x') | lookbehind assertion | (?<=x) |
(!>> 'x') | negated lookahead assertion | (?!x) |
(!<< 'x') | negated lookbehind assertion | (?<!x) |
Capturing groups and references #
Pomsky | Explanation | Regex |
---|
:('foo') | capturing group | (foo) |
:bar('foo') | capturing group named ‘bar’ | (?<bar>foo) |
::1 | reference to 1st capturing group | \1 |
::bar | reference to group named ‘bar’ | \k<bar> |
::-2 | relative backreference | \k<-2> |
::+1 | relative forward reference | |
Wildcard patterns #
Pomsky | Explanation | Regex |
---|
. | any code point except \n | . |
Codepoint , C | any code point | [\s\S] |
Grapheme , G | any grapheme | \X |
Testing #
test {
match 'foo';
match 'the', 'fox', 'the', 'dog'
in 'the quick brown fox jumps over the lazy dog.';
reject 'lazy';
reject in 'lorem ipsum dolor';
}
% [w]{3} %
Comparing capturing groups:
test {
match '13.1.4' as { major: '13', minor: '1', patch: '4' };
match '13.1.4' as { 1: '13', 2: '1', 3: '4' };
}
:major([d]+) '.' :minor([d]+) '.' :patch([d]+)
Modifiers #
Pomsky | Explanation | Regex |
---|
enable lazy; | enable lazy repetition by default | (?U) |
disable lazy; | disable lazy repetition by default | |
enable unicode; | enable Unicode awareness (enabled by default) | |
disable unicode; | disable Unicode awareness | |
Other #
Pomsky | Explanation | Regex |
---|
range '0'-'255' | all decimal numbers from 0 to 255 | |
range '0'-'1FF' base 16 | all hex numbers from 0 to 1FF | |
atomic('foo') | atomic group | (?>foo) |
recursion | recursively match the whole regex | \g<0> |
regex '[]acf-X]' | inline regex | []acf-X] |
Footnotes