我有一个字段可以过滤一些db列。但我无法按需要拆分搜索字符串:
我举了一个例子:
import re
search = ' test "no splits234" this-splits this_not_splits asdf123 '
re.split(r'[\s]*[\W][\s]*', search.strip())
['test', 'no', 'splits234', 'this', 'splits', 'this_not_splits', 'asdf123']
需要此输出:
['test', 'no splits234', 'this', 'splits', 'this_not_splits', 'asdf', '123']
不要拆分引号中的内容,也不要拆分数字中的文本。我该怎么做
可以将
findall
与此正则表达式一起使用:正则表达式详细信息:
"[^"\\]*(?:\\.[^"\\]*)*"
匹配由双引号括起的字符串,忽略所有转义引号李>[^\s-]+
匹配1+非空格、非连字符如果要避免捕获引号,请使用:
更新:
OP还显示最后的
asdf123
分裂成asdf
和123
。为此,以下正则表达式可能起作用:相关问题 更多 >
编程相关推荐