regex - How do I match a certain string that does not contain a certain word? -


i have pretty specific set of requirements defining strings want match, , have following working regex:

/^#\s*([-a-za-z]+)(?=\s|$)/ 

this matches: '# keyword' ... as: '# static keyword'

for final condition, want ignore string if contains word: "static".. i've done lot of digging, , can't figure 1 out. following best attempt:

/^#\s*(?!static)([-a-za-z]+)(?=\s|$)/ 

however, seems though i'm woefully far solution.

you need static in more places right after # , whitespace:

/^#\s*(?!.*static)([-a-za-z]+)(?=\s|$)/ 

by way, might want replace (?=\s|$) \b (a word boundary anchor matches after alphanumeric word). match if punctuation or other whitespace delimits word you're matching.


Comments