完全な文字列を特定のパターンに一致させたい。さんが言ってみましょう:単語が改行文字が続いている場合Python Regex - 改行で文字列を拒否する
word = "aaaa"
test = re.match(r"^aaaa$", word) # this returns True
しかし、:
word = "aaaa\n"
test = re.match(r"^aaaa$", word) # Also returns True :(
しかし、私はそれがこの最後の場合にはFalseを返すための道を見つけたいです。 "\ n"を区別する方法はありますか?
簡単な方法がありますが、 '^ aaaa(?=(?!\ n)$)'は動作します – rock321987