Python Regex - Reject strings with newline

后端 未结 2 841
面向向阳花
面向向阳花 2021-01-21 00:52

I want to match complete strings to a specific pattern. Let\'s say :

word = \"aaaa\"
test = re.match(r\"^aaaa$\", word) # this returns True

Ho

2条回答
  •  轮回少年
    2021-01-21 01:55

    You can use negative lookaheads for checking if it contains a new line character or not.In your case, ^aaaa(?!\n)$.

提交回复
热议问题