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.
*/