match string regex code example

Example 1: js string to regex

const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');

Example 2: regex match exact string

you want to achieve a case insensitive match for the word "rocket" 
surrounded by non-alphanumeric characters. A regex that would work would be:

\W*((?i)rocket(?-i))\W*

Example 3: js match any number string

const match = 'some/path/123'.match(/\/(\d+)/)
const id = match[1] // '123'

Example 4: match regex

const regex = /([a-z]*)ball/g;
const str = "basketball football baseball";
let result;
while((result = regex.exec(str)) !== null) {
	console.log(result[1]); 
    // => basket
    // => foot
    // => base
}

Example 5: regex exact match

use ^ and $ to match the start and end of your string
^matchmeexactly$

Tags:

Misc Example