javascript - Capture words not followed by symbol -
i need capture (english) words except abbreviations pattern are:
"_any-word-symbols-including-dash."
(so there underscore in beginning , dot in end letters , dash in middle)
i tried smthing this:
/\b([a-za-z-^]+)\b[^\.]/g
but seems don't understand how work negative matches.
update:
i need not match wrap words in tags:
"a words _abbr-abrr. here" should get:
<w>a</w> <w>some</w> <w>words</w> _abbr-abbr. <w>a</w> <w>here</w>
so need use replace correct regex:
test.replace(/correct regex/, '<w>$1</w>')
negative lookahead (?!)
.
so can use:
/\b([^_\s]\w*(?!\.))\b/g
unfortunately, there no lookbehind in javascript, can't similar trick "not prefixed _
".
example:
> = "a words _abbr. here" > a.replace(/\b([^_\s]\w*(?!\.))\b/g, "<w>$1</w>") "<w>a</w> <w>some</w> <w>words</w> _abbr. <w>a</w> <w>here</w>"
following comment -
. updated regex is:
/\b([^_\s\-][\w\-]*(?!\.))\b/g > "abc _abc-abc. abc".replace(/\b([^_\s\-][\w\-]*(?!\.))\b/g, "<w>$1</w>") "<w>abc</w> _abc-abc. <w>abc</w>"
Comments
Post a Comment