[英]python split string if new line exists
我有一个简单的字符串,它已经解码为 utf-8 下面是分配给 s 变量的结果字符串
s = "many simple\n% door needed \n1, but color\n2"
我需要使用 \n{only number 0 to 9} regex 拆分这个字符串
我已经尝试过的是
print(s.split(r"\n+[0-9]")) # this is not working.
在上面的字符串中,只有\n1
和\n2
应该发生拆分,但不会发生\n%
那么什么是正确的正则表达式格式来吐出字符串
import re
s = "many simple\n% door needed \n1, but color\n2"
regex = r"\n[0-9]+"
re.split(regex, s)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.