snippetjavascriptTip
Common regular expressions
Viewed 0 times
javascriptcommonexpressionsregular
Problem
- Use the
^and$anchors to match the start and end of the string, respectively. - Add the string you want to match in-between the two anchors.
- Use the
^and$anchors to match the start and end of the string, respectively. - Do not add any characters in-between to match an empty string.
- Use the
\smeta-sequence to match any whitespace character, including spaces, tabs, newlines, etc.
Solution
const regexp = /^abc$/;
// Where 'abc' is the exact string you want to match- Use the
^and$anchors to match the start and end of the string, respectively. - Do not add any characters in-between to match an empty string.
- Use the
\smeta-sequence to match any whitespace character, including spaces, tabs, newlines, etc. - Use the
+quantifier to match one or more occurrences of the previous character. - Add the global flag (
g) to match all occurrences of the pattern in the string. - Depending on the environment, line breaks can be represented in different ways.
Code Snippets
const regexp = /^abc$/;
// Where 'abc' is the exact string you want to matchconst regexp = /^$/;const regexp = /\s+/g;Context
From 30-seconds-of-code: common-regexp-cheatsheet
Revisions (0)
No revisions yet.