最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Regex to replace exact matching string - Stack Overflow

programmeradmin11浏览0评论

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.

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.

Share Improve this question edited Jun 20, 2013 at 9:59 HamZa 14.9k11 gold badges55 silver badges75 bronze badges asked Jun 20, 2013 at 9:52 Sumodh NairSumodh Nair 1,6761 gold badge11 silver badges35 bronze badges 2
  • 2 @te\b ? ............ – zerkms Commented Jun 20, 2013 at 9:54
  • 1 check out, regular-expressions.info for more info on regex patterns and their uses – Liam Commented Jun 20, 2013 at 9:59
Add a comment  | 

2 Answers 2

Reset to default 11

This should work for you:

/\@te\b/

Try this

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

评论列表(0)

  1. 暂无评论