如何使用 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP