inputStr = 'Hi My Name is ~Satish~ L ~Rathore~ , I live in ~Navi Mumbai~.'
Output Should be like each matching text between '~'
'Satish'
'Rathore'
'Navi Mumbai'
inputStr = 'Hi My Name is ~Satish~ L ~Rathore~ , I live in ~Navi Mumbai~.'
Output Should be like each matching text between '~'
'Satish'
'Rathore'
'Navi Mumbai'
1) You can easily achieve the result using Regular expression as:
/~[\w\s]+~/g
const inputStr =
'Hi My Name is ~Satish~ L ~Rathore~ , I live in ~Navi Mumbai~.';
const result = inputStr
.match(/~[\w\s]+~/g)
.map((s) => s.slice(1, s.length - 1));
console.log(result);
2) You can also do as:
/~[^~]+~/g
const inputStr =
'Hi My Name is ~Satish~ L ~Rathore~ , I live in ~Navi Mumbai~.';
const result = inputStr.match(/~[^~]+~/g).map((s) => s.slice(1, s.length - 1));
console.log(result);