Python regex to match words not having dot

前端 未结 5 1194
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-26 15:38

I want to accept only those strings having the pattern \'wild.flower\', \'pink.flower\',...i.e any word preceding \'.flower\', but the word should not contain dot. For example,

5条回答
  •  遥遥无期
    2021-01-26 16:38

    To match any character except a newline or a dot you could use a negated character class [^.\r\n]+ and repeat that one or more times and use anchors to assert the start ^ and the end $ of the line.

    ^[^.\r\n]+\.flower$

    Or you could specify in a character class which characters you would allow to match followed by a dot \. and flower.

    ^[a-z0-9]+\.flower$

提交回复
热议问题