Regular Expression Tester

The main cascading style sheet has not loaded, so this page will not display properly

String
Regular Expression  /    Attributes
Replacement
String.match(RegExp)   String.search(RegExp)   RegExp.lastMatch  
RegExp.input  
RegExp.leftContext   RegExp.rightContext  
RegExp.$1   RegExp.$2   RegExp.$3   RegExp.$4   RegExp.$5  
RegExp.$6   RegExp.$7   RegExp.$8   RegExp.$9   RegExp.lastParen  
After Replacement  
Enter test string and regular expression, then click Test to view operation on string

Guidance

Regular Expressions

Character set: [ABC] = any character listed; [^abc] = not any character listed; [\w\W] = any character including newline; [A-Z] = range of characters

Escaped characters: \f = formfeed; \n = newline; \r = carriage return; \t = tab; \v = vertical tab; also those in regular expression syntax \ / [ - ] . ? * + { } ^ $ ( ) | for example \\

Metacharacters: \d = digit = [0-9]; \D = not digit; \s = single space (including \t etc); \S = not space; \w = letter, digit or underscore = [A-Za-z0-9_]; \W = not letter, digit or underscore; . = any character except newline

Position metacharacters: ^ = beginning of string or line; $ = end of string or line; \b = word boundary; \B = not word boundary (match no characters)

Grouping: (x) = groups content, may be nested and sets RegExp.$#, \# in regexp and $# in replacement counted by ( unless (?:x) = non capturing; | = alternatives

Replacement: $` = left context; $& = whole match; $# = #th capturing group; $' = right context

Assertions: (x?=y) = x if followed by y; (x?!y) = x if not followed by y; (?<=y)x = x preceded by y; (?<!y)x = x not preceded by y (only x is matched)

Counts of preceding character / group: ? = 0 or 1; * = 0 or more; + = 1 or more; {n} = exactly n times; {n,} = n or more times; {n,m} = at least n, at most m times; matching is greedy unless count followed by ?, eg, +?

Greediness: regular expressions match as much as possible in the string while the entire expression still matches unless counts are made lazy to match as little as possible by appending ?, eg, +?

Attributes

Attributes: g = global, i = case insensitive, m = multi-line