8

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.

2
  • 2
    @te\b ? ............ Commented Jun 20, 2013 at 9:54
  • 1
    check out, regular-expressions.info for more info on regex patterns and their uses Commented Jun 20, 2013 at 9:59

2 Answers 2

11

This should work for you:

/\@te\b/
Sign up to request clarification or add additional context in comments.

1 Comment

Great. If you could mark this as the correct answer, that would be awesome.
2

Try this

var a = '@test @te @world @dimension';
var b = a.replace(/@te /, '');

2 Comments

Exactly what isn't a regular expression?
I think this is what OP wants. OP has tagged javascript and asked help to replace desired string with his choice so I gave this example.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.