「Python」- 正则表达式

使用 re.match 匹配中文

#!/usr/bin/python2.7
# encoding=utf8
import re

testString = u"--story=10000 --user=风清扬 测试"
testString = unicode("--story=10000 --user=风清扬 测试", "utf-8")

matched = re.match(ur"--story=(\d+)\s+--user=([\u4e00-\u9fa5 ]+)\s*$", testString)
print(matched.group()) # --story=10000 --user=风清扬 测试
print(matched.group(0)) # --story=10000 --user=风清扬 测试

参考文献

Python: Check if a string contains chinese character?
Find all Chinese text in a string using Python and Regex
参考Python2.7的re库
How to convert a string to utf-8 in Python
Python 3/Regular Expression HOWTO