javascript - How can I match first letter of every word except words in braces with Regex -
i've been trying forever. can match first letter of every word, can't exclude words in braces.
for example:
i can't (do) this, please (help) me.
so should match - i
, c
, t
, p
, m
- only.
using \b\w
matches first letters of word, doesn't exclude words in braces. i've tried negative lookahead, seems can't properly:
(?!\(()\))\b\w
also i've got problem unicodes. using (?:^| )[a-z]{1}
or \b\w
matches latin letters , have different unicodes, example:
i (someone) ვიღაც.
and in situation regex match i
, a
, s
, not ვ
. thanks
different things considered.
first need define letters can non-latin ones. see answer , comments. match letter let's use
[\u00c0-\u1fff\u2c00-\ud7ff\w]
as want in javascript, regex limited. word boundary
\b
cannot used not match specified letter range. lookbehind not available. need use negated class of specified letter.(?:^|[^'\u00c0-\u1fff\u2c00-\ud7ff\w-])
"word boundary". here added'
avoid matches in suchcan't
use lookahead checking outside of parenthesis:
(?![^(]*\))
all pattern like
(?:^|[^'\u00c0-\u1fff\u2c00-\ud7ff\w])([\u00c0-\u1fff\u2c00-\ud7ff\w])(?![^(]*\))
Comments
Post a Comment