Play on GitHub

Composed Regular Expression ($(regex_version)):     Analyze
Code:

Doc:

"^" Matches beginning of input. If the multiline flag is set to true, also matches immediately after a line break character.

For example, /^A/ does not match the 'A' in "an A", but does match the 'A' in "An E".

The "^" has a different meaning when it appears as the first character in a character set pattern.

Example: composer.SOL();

"$" Matches end of input. If the multiline flag is set to true, also matches immediately before a line break character.

For example, /t$/ does not match the 't' in "eater", but does match it in "eat". Example: composer.EOL();

"\d" Matches any single digit character.

Example: composer.digit();

"\D" Matches any single non-digit character.

Example: composer.digit(false);

"\w" Matches any single word character.

Example: composer.word();

"\W" Matches any single non-word character.

Example: composer.word(false);

Matches a literal string (escaped appropriately).

Example: composer.literal("**aabb**");

"*" Matches the preceding character 0 or more times.

For example, /bo*/ matches 'boooo' in "A ghost booooed" and 'b' in "A bird warbled", but nothing in "A goat grunted".

Example: composer.zeroOrMore(); (greedy)

Example: composer.zeroOrMore(false); (non-greedy)

"+" Matches the preceding character 1 or more times. Equivalent to {1,}.

For example, /a+/ matches the 'a' in "candy" and all the a's in "caaaaaaandy".

Example: composer.oneOrMore(); (greedy)

Example: composer.oneOrMore(false); (non-greedy)

"?" Matches the preceding character 0 or 1 time. Equivalent to {0,1}.

For example, /e?le?/ matches the 'el' in "angel" and the 'le' in "angle" and also the 'l' in "oslo".

If used immediately after any of the quantifiers *, +, ?, or {}, makes the quantifier non-greedy (matching the fewest possible characters), as opposed to the default, which is greedy (matching as many characters as possible). For example, applying /\d+/ to "123abc" matches "123". But applying /\d+?/ to that same string matches only the "1".

Also used in lookahead assertions, as described in the x(?=y) and x(?!y) below.

Example: composer.zeroOrOne(); (greedy)

Example: composer.zeroOrOne(false); (non-greedy)

"{n}" Matches exactly n occurrences of the preceding character. N must be a positive integer.

For example, /a{2}/ doesn't match the 'a' in "candy," but it does match all of the a's in "caandy," and the first two a's in "caaandy."

"{n, m}" Where n and m are positive integers. Matches at least n and at most m occurrences of the preceding character. When m is zero, it can be omitted.

For example, /a{1,3}/ matches nothing in "cndy", the 'a' in "candy," the first two a's in "caandy," and the first three a's in "caaaaaaandy" Notice that when matching "caaaaaaandy", the match is "aaa", even though the original string had more a's in it.

Example: composer.repeat(min, max); (greedy)

Example: composer.repeat(min, max, false); (non-greedy)

"(x)" Matches 'x' and remembers the match, as the following example shows. The parentheses are called capturing parentheses.

The '(foo)' and '(bar)' in the pattern /(foo) (bar) \1 \2/ match and remember the first two words in the string "foo bar foo bar". The \1 and \2 in the pattern match the string's last two words. Note that \1, \2, \n are is used in the matching part of the regex. In the replacement part of a regex the syntax $1, $2, $n must be used, e.g.: 'bar foo'.replace( /(...) (...)/, '$2 $1' ).

Example: composer.group(); (start of group)

Example: composer.end(); (end of group)

"(?P<y>x)" Matches 'x' and remembers the match as group name 'y' (alogn with its group number), as the following example shows. The parentheses are called capturing parentheses.

The '(?P<foo>foo)' and '(?P<bar>bar)' in the pattern /(?P<foo>foo) (?P<bar>bar) \1 (?P=bar)/ match and remember the first two words in the string "foo bar foo bar" with group names "foo" and "bar" respectively. Note that (?P=bar) are is used in the matching part of the regex as a named back-reference (see below)..

Example: composer.namedGroup(name); (start of named group)

Example: composer.group({'name':name}); (start of named group)

Example: composer.end(); (end of named group)

"(?:x)" Matches 'x' but does not remember the match. The parentheses are called non-capturing parentheses, and let you define subexpressions for regular expression operators to work with. Consider the sample expression /(?:foo){1,2}/. Without the non-capturing parentheses, the {1,2} characters would apply only to the last 'o' in 'foo'. With the capturing parentheses, the {1,2} applies to the entire word 'foo'.

Example: composer.nonCaptureGroup(); (start of group)

Example: composer.group({'nocapture':true}); (start of group)

Example: composer.end(); (end of group)

"x(?=y)" Matches 'x' only if 'x' is followed by 'y'. This is called a lookahead.

For example, /Jack(?=Sprat)/ matches 'Jack' only if it is followed by 'Sprat'. /Jack(?=Sprat|Frost)/ matches 'Jack' only if it is followed by 'Sprat' or 'Frost'. However, neither 'Sprat' nor 'Frost' is part of the match results.

"x(?!y)" Matches 'x' only if 'x' is not followed by 'y'. This is called a negated lookahead.

For example, /\d+(?!\.)/ matches a number only if it is not followed by a decimal point. The regular expression /\d+(?!\.)/.exec("3.141") matches '141' but not '3.141'.

Example: composer.lookAheadGroup(true|false); (start of group)

Example: composer.group({'lookahead':true|false}); (start of group)

Example: composer.end(); (end of group)

"x(?<=y)" Matches 'x' only if 'x' is preceded by 'y'. This is called a lookabehind.

For example, /Jack(<?=Sprat)/ matches 'Jack' only if it is preceded by 'Sprat'.

"x(?<!y)" Matches 'x' only if 'x' is not preceded by 'y'. This is called a negated lookabehind.

For example, /\d+(?<!0)/ matches a number only if it is not preceded by a zero.

Note that JavaScript Regular Expressions do not currently support lookbehinds!
Example: composer.lookBehindGroup(true|false); (start of group)

Example: composer.group({'lookbehind':true|false}); (start of group)

Example: composer.end(); (end of group)

"\n" Literaly matches a previous group identified by group number n. This is an indexed back reference to an already parsed and matched result that is grouped.

"(?P=name)" Literaly matches a previous group identified by group name name. This is an named back reference to an already parsed and matched result that is grouped.

For example, /(a*)b+\1/ matches 'bbbb' and 'aaabbaaa' with an indexed back reference.

For example, /(?P<alpha>a*)b+(?P=alpha)/ matches 'bbbb' and 'aaabbaaa' with a named back reference.

Example: composer.backReference( n ); (insert back reference)

"x|y" Matches either 'x' or 'y' (without wrapping in a group).

For example, /green|red/ matches 'green' in "green apple" and 'red' in "red apple."

Example: composer.either(); (start of alternation)

Example: composer.end(); (end of alternation)

"[xyz]" Character set. This pattern type matches any one of the characters in the brackets, including escape sequences. Special characters like the dot(.) and asterisk (*) are not special inside a character set, so they don't need to be escaped. You can specify a range of characters by using a hyphen, as the following examples illustrate.

The pattern [a-d], which performs the same match as [abcd], matches the 'b' in "brisket" and the 'c' in "city". The patterns /[a-z.]+/ and /[\w.]+/ match the entire string "test.i.ng".

"[^xyz]" A negated or complemented character set. That is, it matches anything that is not enclosed in the brackets. You can specify a range of characters by using a hyphen. Everything that works in the normal character set also works here.

For example, [^abc] is the same as [^a-c]. They initially match 'r' in "brisket" and 'h' in "chop."

Example: composer.characterGroup(true|false); (start of group)

Example: composer.group({'characters':true|false}); (start of group)

Example: composer.end(); (end of group)

x, y, z Specify a set of characters to be matched in a character group.

Example: composer.characters("x", "y", "z");

"x", "z" Specify a range of characters to be matched in a character group. Results in [x-z]

Example: composer.range("x", "z");