Answers for "how to make the regex return the sentence it has matched without the regex"

0

how to make the regex return the sentence it has matched without the regex

const checkString = (string)=>{

let regex  = /regex/

if(regex.test(string)){
    let newArray = string.split(' ')
let index = newArray.indexOf('regex')
newArray.splice(index , 1)
return newArray.join(' ')
}
}
let string = 'solution regex solution'
console.log(checkString(string))

/* This code will remove the first occurance of the regex and return 
the rest of the string.
*/
Posted by: Guest on October-14-2021

Code answers related to "how to make the regex return the sentence it has matched without the regex"

Code answers related to "Javascript"

Browse Popular Code Answers by Language