I have string like this:
var str = "Hello (World) I'm Newbie";
how to get World from string above using RegExp?, I'm sorry I don't understand about regex.
Thank's
I have string like this:
var str = "Hello (World) I'm Newbie";
how to get World from string above using RegExp?, I'm sorry I don't understand about regex.
Thank's
Assuming that there will be atleast one such word, you can do it using String#match. The following example matches the words between parentheses.
console.log(
"Hello (World) I'm Newbie"
.match(/\(\w+\)/g)
.map(match => match.slice(1, -1))
)
Rather than using a regex - use .split()...Note the escaped characters in the splits. The first split gives "World) I'm Newbie" and the second gives "World".
var str = "Hello (World) I'm Newbie";
var strContent = str.split('\(')[1].split('\)')[0];
console.log(strContent); // gives "World"
This might help you for your regex
\w match whole world+ plus with another regex[] starts group^ except(World) matching wordvar str = "Hello (World) I'm Newbie";
var exactword=str.replace(/\w+[^(World)]/g,'')
var filtered = str.replace(/(World)/g,'')
alert(exactword)
alert(filtered)