HomeToolsAbout

Regex Basics

What is it

Regular expressions (regexps) are patterns which describe the contents of a string. They're used for testing whether a string contains a given pattern, or extracting the portions that match.

Quantifier ?

The ? (quantifier) makes the preceding token in the regular expression optional

# matches both colour and color colou?r # matches Nov and November Nov(ember)?

Applying in JS

const method1 = new RegExp(/^---([\s\S]*?)---/).exec(someString); const method2 = someString.match(/^---([\s\S]*?)---/);
AboutContact