patrickxx patrickxx - 4 days ago 4x
Javascript Question

Regex: I want to match only words without a dot at the end

For example: George R.R. Martin
I want to match only George and Martin.

I have tried:

But doesn't work!


The \w+\b. matches 1+ word chars that are followed with a word boundary, and then any char that is a non-word char (as \b restricts the following . subpattern). Note that this way is not negating anything and you miss an important thing: a literal dot in the regex pattern must be escaped.

You may use a negative lookahead (?!\.):

var s = "George R.R. Martin";

See the regex demo


  • \b - leading word boundary
  • \w+ - 1+ word chars
  • \b - trailing word boundary
  • (?!\.) - there must be no . after the last word char matched.

See more about how negative lookahead works here.