简体   繁体   中英

How to do regex match on subset of dotted-notation strings

I want to match multi-dot-notation expressions but ignore them if they're in lines where they're:

- inside a particular string like 'consts'
- inside a comment
- inside a quoted string

So I DON'T want to match anything on these 3 lines

a.b.consts.d.e
comment line 'a.b.c.d
quote line "a.b.c.d"

But DO want to match parts of these 3 lines

asdf a.b.c.d
a.b c.d .e c.d.e
long a.b.c.d.e.f.g

I've tried a number lookahead/behind/negatives ideas with partial success but nothing that hits all the conditions at once.

See one regex attempt here, which uses the above description text as the actual text to match against: https://regex101.com/r/dSinUs/6

This can help you, it is a little complex but it do the work

^\b((?!\.\w{2,}\.)[^"'])+(\s*\w{1}\s*\.)+\w$

https://regex101.com/r/dSinUs/7

This expression would likely fail in many instances because of [az.\\s]* , but it might provide a different perspective as to how we'd start solving this complicated problem, which yet I'm unsure what might be desired or undesired:

^(?!(.*["'])|(.*[a-z]\.consts\.[a-z].*))[a-z.\s]*$

Demo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM