2024-10-01 05:01:45 发布
网友
在regex中,例如在Python中使用:
WORD = re.compile(r'\w+')
然后使用:
我得到:
['This', 'is', 'a', 'test']
现在我想把half-space字符,它是\u200c作为普通的字母数字字符,所以如果我有:
half-space
\u200c
w = 'This\u200cis a test'
然后当我运行WORD.findall(w)时,我得到:
WORD.findall(w)
['This\u200cis', 'a', 'test']
我怎么能做到呢?在
使用character classes除了\w(Python 3.x+),还包括{}:
\w
>>> import re >>> re.findall(r'[\u200c\w]+', 'This\u200cis a test') ['This\u200cis', 'a', 'test']
在Python 2.x中,需要使用unicode:
使用character classes除了}:
\w
(Python 3.x+),还包括{在Python 2.x中,需要使用unicode:
^{pr2}$相关问题 更多 >
编程相关推荐