python - Need help in pattern matching -


problem: sentence starts hi (case insensitive) , not followed space , letter d.

my regex: [hi|hi|hi|hi][^ d|d][a-za-z ]*

however, don't understand why string hi dave how doing getting accepted regex.

i using python re library this.
try: have tried different versions [^ ][^d|d], none of these seem work.

you can't use alternation inside of character class. character class defines set of characters. saying — "match 1 character specified class". easiest way implement negative lookahead while utilizing inline (?i) case-insensitive modifier , anchoring.

(?i)^hi(?! d).* 

explanation:

(?i)     # set flags block (case-insensitive)  ^        # beginning of string  hi      #   'hi'  (?!     #   ahead see if there not:    d     #     ' d'  )       #   end of look-ahead .*       # character except \n (0 or more times) 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

datatable - Matlab struct computations -