0

I am trying to split a string using regex on $ symbol but the output is not what I want.

string = "43$hello"
list_of_splits = re.split("$",string)

Output:
['43$hello','']

Output I want:
['43','hello']

It's visible by the output that "$" is a special character in regex, but now by how can I do this?

2 Answers2

0

You can just use string split method.

string = "43$hello"
string.split("$")

Output

['43', 'hello']

Anurag Dhadse
  • 1,722
  • 1
  • 13
  • 26
0

Use the escape character \ : list_of_splits = re.split("\$", str)

keijeizei
  • 80
  • 4