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.

  1. first need define letters can non-latin ones. see answer , comments. match letter let's use [\u00c0-\u1fff\u2c00-\ud7ff\w]

  2. 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 such can't

  3. use lookahead checking outside of parenthesis: (?![^(]*\))

all pattern like

(?:^|[^'\u00c0-\u1fff\u2c00-\ud7ff\w])([\u00c0-\u1fff\u2c00-\ud7ff\w])(?![^(]*\)) 

see fiddle , demo @ regex101


Comments

Popular posts from this blog

matlab - error with cyclic autocorrelation function -

django - (fields.E300) Field defines a relation with model 'AbstractEmailUser' which is either not installed, or is abstract -

c# - What is a good .Net RefEdit control to use with ExcelDna? -