This code not running when put Textx-yz but runs fine when put Textx-y
I want to alert when same string match also
alert('Textabc Textx-yz TextTypeTestingText'.match(/Textx-yz\S /)[0])
CodePudding user response:
you can use word boundaries and exact match to get this match:
\b(Textx\-yz) \b
\b
- searches whole words only
and in between we tell it what we want to find
CodePudding user response:
If I understand what you mean you can this pattern:
'Textabc Textx-yz TextTypeTestingText'.match(/Textx-yz \S /)[0]
Actually I add a space after -yz
in match method