Syntax meaning | Syntax | Regex Match | Expected Match |
Start/Stop regex | / | /^www\.orig\.domain\.com$/ | www.orig.domain.com |
Start Selection | ^ | /^www\.orig\.domain\.com$/ | www.orig.domain.com |
End Selection | $ | /^www\.orig\.domain\.com$/ | www.orig.domain.com |
Next character is literal, not a regex character | \ | /^www\.orig\.domain\.com$/ | www.orig.domain.com |
Single Character | . | /^t.s.s.r.n.$/ | teststring |
. | /^.e.t.t.i.g$/ | teststring | |
Single Digit | \d | /^teststring\d\d\d$/ | teststring123 |
Any word character (equal to [a-z A-Z 0-9 _ ]) | \w | /^teststrin\w\w\w3$/ | teststring123 |
Wildcard (regex any single character = ".", 0 or more times = "*") | .* | /^teststr.*/ | teststring123 |
Capture Groups, for example (ABC)(XYZ)(.*) To capture something it needs to be in parentheses "( )", each capture group is numbered starting with 1, the syntax to use this capture group is "/#" e.g. /1, /2, /3 etc |
|||
Regex Match String | Regex Replace with | Expected Output | |
To reuse capture group 1 "(orig)", the syntax is /1 (orig) | /^www\.(orig)\.(domain)\.(com)$/ | /1.company.net | orig.company.net |
To reuse capture group 2 "(domain)", the syntax is /2(domain) | /^www\.(orig)\.(domain)\.(com)$/ | new./2.net | new.domain.net |
To reuse capture group 3 "(com)", the syntax is /3(com) | /^www\.(orig)\.(domain)\.(com)$/ | new.company./3 | new.company.com |