Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

js string to regex

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

string to regex javascript

function stringToRegex(s, m) {
  return (m = s.match(/^([/~@;%#'])(.*?)1([gimsuy]*)$/)) ? new RegExp(m[2], m[3].split('').filter((i, p, s) => s.indexOf(i) === p).join('')) : new RegExp(s);
}

console.log(stringToRegex('/(foo)?/bar/i'));
console.log(stringToRegex('#(foo)?/bar##gi')); //Custom delimiters
console.log(stringToRegex('#(foo)?/bar##gig')); //Duplicate flags are filtered out
console.log(stringToRegex('/(foo)?/bar')); // Treated as string
console.log(stringToRegex('gig')); // Treated as string
 Run code snippetHide results
Comment

convert string to regular expression js

// Let's say you do str.matchAll(char) but char is ) or @, etc. This will throw an error.
// That's is why, before matchAll, we must escape the string like that:
str = str.replace(/[|{}()[]^$+*?.]/g, '$&')
Comment

PREVIOUS NEXT
Code Example
Javascript :: add comma after every 3 digits javascript 
Javascript :: puppeteer get attribute 
Javascript :: jsp include html 
Javascript :: javascript remove single class from element 
Javascript :: for each jquery 
Javascript :: iframe chrome devtool 
Javascript :: javascript remove item onclick 
Javascript :: javascript update local storage array 
Javascript :: VM1188:1 Uncaught TypeError: $ is not a function at <anonymous:1:1 
Javascript :: how to disable back js 
Javascript :: how to use url parameters in react 
Javascript :: last element in javascript 
Javascript :: new line in react js 
Javascript :: react native change app name 
Javascript :: make first letter capital 
Javascript :: react native text ellipsis 
Javascript :: check if any property of object is null javascript 
Javascript :: react use same useState for multiple inputs 
Javascript :: js camalcase 
Javascript :: javascript check if a number is even or odd 
Javascript :: This is the RegEx for Roman numerals 
Javascript :: javascript sort array of objects by key value 
Javascript :: js merge 2 lists 
Javascript :: moment format date 
Javascript :: jshint esversion 6 
Javascript :: node js starting template 
Javascript :: html parser javascript 
Javascript :: tsconfig.json not generated 
Javascript :: window.location.href is not a function 
Javascript :: javascript math.random 
ADD CONTENT
Topic
Content
Source link
Name
5+1 =