* feat(new tool): Regex Tester Fix https://github.com/CorentinTh/it-tools/issues/1007, https://github.com/CorentinTh/it-tools/issues/991, https://github.com/CorentinTh/it-tools/issues/936, https://github.com/CorentinTh/it-tools/issues/761, https://github.com/CorentinTh/it-tools/issues/649 https://github.com/CorentinTh/it-tools/issues/644, https://github.com/CorentinTh/it-tools/issues/554 https://github.com/CorentinTh/it-tools/issues/308 * fix: refactor to service + add regex diagram + ui enhancements * fix: update queryParams * fix: deps * fix: svg style bug in @regexper/render @regexper/render use a stylesheet in svg that cause bugs in whole site. So add regexper in a shadow root * feat(new tool): added Regex Cheatsheet * Update src/tools/regex-memo/index.ts * Update src/tools/regex-tester/index.ts --------- Co-authored-by: Corentin THOMASSET <corentin.thomasset74@gmail.com>
		
			
				
	
	
	
		
			3.2 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			3.2 KiB
		
	
	
	
	
	
	
	
Normal characters
| Expression | Description | 
|---|---|
| .or[^\n\r] | any character excluding a newline or carriage return | 
| [A-Za-z] | alphabet | 
| [a-z] | lowercase alphabet | 
| [A-Z] | uppercase alphabet | 
| \dor[0-9] | digit | 
| \Dor[^0-9] | non-digit | 
| _ | underscore | 
| \wor[A-Za-z0-9_] | alphabet, digit or underscore | 
| \Wor[^A-Za-z0-9_] | inverse of \w | 
| \S | inverse of \s | 
Whitespace characters
| Expression | Description | 
|---|---|
|   | space | 
| \t | tab | 
| \n | newline | 
| \r | carriage return | 
| \s | space, tab, newline or carriage return | 
Character set
| Expression | Description | 
|---|---|
| [xyz] | either x,yorz | 
| [^xyz] | neither x,ynorz | 
| [1-3] | either 1,2or3 | 
| [^1-3] | neither 1,2nor3 | 
- Think of a character set as an ORoperation on the single characters that are enclosed between the square brackets.
- Use ^after the opening[to “negate” the character set.
- Within a character set, .means a literal period.
Characters that require escaping
Outside a character set
| Expression | Description | 
|---|---|
| \. | period | 
| \^ | caret | 
| \$ | dollar sign | 
| | | pipe | 
| \\ | back slash | 
| \/ | forward slash | 
| \( | opening bracket | 
| \) | closing bracket | 
| \[ | opening square bracket | 
| \] | closing square bracket | 
| \{ | opening curly bracket | 
| \} | closing curly bracket | 
Inside a character set
| Expression | Description | 
|---|---|
| \\ | back slash | 
| \] | closing square bracket | 
- A ^must be escaped only if it occurs immediately after the opening[of the character set.
- A -must be escaped only if it occurs between two alphabets or two digits.
Quantifiers
| Expression | Description | 
|---|---|
| {2} | exactly 2 | 
| {2,} | at least 2 | 
| {2,7} | at least 2 but no more than 7 | 
| * | 0 or more | 
| + | 1 or more | 
| ? | exactly 0 or 1 | 
- The quantifier goes after the expression to be quantified.
Boundaries
| Expression | Description | 
|---|---|
| ^ | start of string | 
| $ | end of string | 
| \b | word boundary | 
- How word boundary matching works:
- At the beginning of the string if the first character is \w.
- Between two adjacent characters within the string, if the first character is \wand the second character is\W.
- At the end of the string if the last character is \w.
 
- At the beginning of the string if the first character is 
Matching
| Expression | Description | 
|---|---|
| foo|bar | match either fooorbar | 
| foo(?=bar) | match fooif it’s beforebar | 
| foo(?!bar) | match fooif it’s not beforebar | 
| (?<=bar)foo | match fooif it’s afterbar | 
| (?<!bar)foo | match fooif it’s not afterbar | 
Grouping and capturing
| Expression | Description | 
|---|---|
| (foo) | capturing group; match and capture foo | 
| (?:foo) | non-capturing group; match foobut without capturingfoo | 
| (foo)bar\1 | \1is a backreference to the 1st capturing group; matchfoobarfoo | 
- Capturing groups are only relevant in the following methods:
- string.match(regexp)
- string.matchAll(regexp)
- string.replace(regexp, callback)
 
- \Nis a backreference to the- Nthcapturing group. Capturing groups are numbered starting from 1.