【发布时间】:2021-06-01 14:05:01
【问题描述】:
我正在尝试在 $ 符号上使用正则表达式拆分字符串,但输出不是我想要的。
string = "43$hello"
list_of_splits = re.split("$",string)
Output:
['43$hello','']
Output I want:
['43','hello']
从输出中可以看出“$”是正则表达式中的一个特殊字符,但现在我该怎么做呢?
【问题讨论】:
-
No regex is required,使用
"43$hello".split('$')。否则,转义$。