0

I'm a newbie Python learner and having some issues while making practice on string operations.

Code:

string = 'param1/param2:\d+/param3'
print(string.split('/'))

Expected Result:

['param1', 'param2:\d+', 'param3']

Actual Result:

['param1', 'param2:\\d+', 'param3']

How can I prevent Python to prepend extra backslash to the backslash where this issue can be seen at the second element of the result array?

onanmco
  • 11
  • 2

1 Answers1

0

In python "\" actually is "\\" you can read this link for more details but maybe this code help you:

string = 'param1/param2:\d+/param3'
print(string.split('/')[1].replace("\\","\\"))

Output:

param2:\d+
I'mahdi
  • 11,310
  • 3
  • 17
  • 23