如何使用 Python 正則表示式匹配除空格和換行符以外的任何內容?
以下程式碼使用正則表示式匹配給定字串中除空格和換行符以外的任何內容。
示例
import re print re.match(r'^[^ \n]*$', """IfindTutorialspointuseful""") print re.match(r'^[^ \n]*$', """I find Tutorialspointuseful""") print re.match(r'^[^ \n]*$', """Ifind Tutorialspointuseful""")
輸出
輸出為
<_sre.SRE_Match object at 0x00000000048965E0> None None
廣告