javascript regex example match
//Declare Reg using slash
let reg = /abc/
//Declare using class, useful for buil a RegExp from a variable
reg = new RegExp('abc')
//Option you must know: i -> Not case sensitive, g -> match all the string
let str = 'Abc abc abc'
str.match(/abc/) //Array(1) ["abc"] match only the first and return
str.match(/abc/g) //Array(2) ["abc","abc"] match all
str.match(/abc/i) //Array(1) ["Abc"] not case sensitive
str.match(/abc/ig) //Array(3) ["Abc","abc","abc"]
//the equivalent with new RegExp is
str.match('abc', 'ig') //Array(3) ["Abc","abc","abc"]
Also in JavaScript:
- javascript print
- keycode
- text align-center js
- how to count duplicates in an array javascript
- react native backgrunde img
- express js limit access based on rate
- javascript object total
- redirect with javascript
- javacript is checkbox checked
- javascript get the last item in an array
- generate unique id javascript
- today's time in javascript
- ontouch validate angular
- toLocalString
- jquery submit form on enter
- sleep js
- js object keys
- jest it vs test
- jquery sort select options by text
- replace all character in string javascript
- how can we take selected index value of dropdown in javascript
- react dropdown menu stack overflow
- document queryselectorall and map javacript
- check if string contains substring javascript