Python正则表达式匹配isalnum()和isspace()的任意组合,但不匹配两个同时换行符
我想分手Python正则表达式匹配isalnum()和isspace()的任意组合,但不匹配两个同时换行符,python,regex,Python,Regex,我想分手 "Use a regexp that matches any combination\nthat satisfies Python's\n\nisalphanumeric() or isspace() functions, but not two simultanionus\nnewline symbols" 变成 ["A regexp that matches any combination\nthat satisfies Python", "s ", "isalphanum
"Use a regexp that matches any combination\nthat satisfies Python's\n\nisalphanumeric() or isspace() functions, but not two simultanionus\nnewline symbols"
变成
["A regexp that matches any combination\nthat satisfies Python", "s ", "isalphanumeric", "or isspace", " functions"," but not two simultanionus\nnewline symbols"]
使用findall()方法列出
我写过:
re.findall("[\w\s]*", text)
但是现在我需要添加一些类似于“除\n\n之外”的内容,以满足我的表达
([\w\s]+?)(?=\n{2}|['(),]|$)
试试这个。看演示。使用匹配而不是拆分
这个
re.findall(“[\w]+”,text)
就可以了。那么它如何匹配一个换行符呢?你需要解释得更清楚些。
re.findall("([\w\s]+?)(?=\n{2}|['(),]|$)", text)