string to regex javascript code example
Example 1: js string to regex
const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');
Example 2: js match any number string
const match = 'some/path/123'.match(/\/(\d+)/)
const id = match[1]
Example 3: using regex in javascript
var regex = /\s/g;
var regex = new RegExp("\s", "g");
Example 4: how to use the match function in javascript for regex
const str = 'For more information, see Chapter 3.4.5.1';
const re = /see (chapter \d+(\.\d)*)/i;
const found = str.match(re);
console.log(found);
Example 5: regex for strings with specific letters javascript
let re = /ab+c/;
Example 6: regular expression javascript
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
console.log("Look mam, I can regex!");
}