I want a regex expression to replace the string which exactly matches it.
For e.g : - var a = '@test @te @world @dimension
'
I need to replace '@te
' .
Since '@te
' exists in @test
as well so Replace statement is replacing the @test
in my case.
So could anyone please let me know how can this be done.
Just the exact matching string needs to be replaced.
We can match an exact string with JavaScript by using the JavaScript string's match method with a regex pattern that has the delimiters for the start and end of the string with the exact word in between those.
The Regex. Replace(String, MatchEvaluator, Int32, Int32) method is useful for replacing a regular expression match if any of the following conditions is true: The replacement string cannot readily be specified by a regular expression replacement pattern.
For example, the replacement pattern $1 indicates that the matched substring is to be replaced by the first captured group.
This should work for you:
/\@te\b/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With