牛骨文教育服务平台(让学习变的简单)
博文笔记

Python 正则表达式限定输入为特定字符

创建时间:2014-07-23 投稿人: 浏览次数:176

Regex Expression

# alphanumber
^[a-zA-Z0-9]+$

# ASCII character
^[x00-x7F]+$

# ASCII noncontrol characters and line break
^[

x20-x7E]+$

# shared ISO-8859-1 and windows-1252 characters
^[x00-x7FxA0-xFF]+$

# alphanumber in any language
^[^W_]+$

CODE:

import re
if re.match("^[a-zA-Z0-9]+$", subject):
	# Successful match at the start of the string
else:
	# Match attempt failed


声明:该文观点仅代表作者本人,牛骨文系教育信息发布平台,牛骨文仅提供信息存储空间服务。