If you just want to check if a newline (\n
) is present, you can just use Python’s in
operator to check if it’s in a string:
>>> "\n" in "hello\ngoodbye"
True
… or as part of an if
statement:
if "\n" in foo:
print "There's a newline in variable foo"
You don’t need to use regular expressions in this case.