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 :: img src to file javascript 
Javascript :: nodejs open file 
Javascript :: js subarray 
Javascript :: es6 convert array to object 
Javascript :: recursive function for fibonacci series in java javascript 
Javascript :: disable button 
Javascript :: js length of longest array in 2d array 
Javascript :: sequelize findorcreate 
Javascript :: mongoBD increment 
Javascript :: concatenate multiple arrays javascript 
Javascript :: materialize open modal on load 
Javascript :: substr() javascript 
Javascript :: async javascript 
Javascript :: url validation in formcontrol angular 8 
Javascript :: Could not find a production build in the 
Javascript :: date difference moment js 
Javascript :: debounce javascript 
Javascript :: read multiple parameters in url in js 
Javascript :: cambiar background image javascript 
Javascript :: http get response body node js 
Javascript :: jquery wait for element to load 
Javascript :: scroll to element in scrollable div 
Javascript :: javascriopt initialize 2d array with size 
Javascript :: from string to number js 
Javascript :: javascript object 
Javascript :: print whole array javascript 
Javascript :: sweetalert allow html 
Javascript :: momentjs display timezone 
Javascript :: how to get date in footer javascript 
Javascript :: javascript array to string with comma 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =