0
var text = 'word otherword';

I want to select words that only matches with 'word'. When i use simply /word/ for regex pattern, then it also selects the 'word' part in 'otherword'. I dont need that word(in this case 'otherword').So how can i only select/match 'word' word using regex?

tablex
  • 87
  • 1
  • 11

1 Answers1

2

Use word boundary - \b.

/\bword\b/
JNF
  • 3,696
  • 3
  • 31
  • 64