How to split a line with multiple delimiters and find out which delimiter was used to split the line with maxsplit by 1.
import re
string ="someText:someValue~"
re.split(":|~",string,1)
returns ['someText', 'someValue~']. In this case, ":" was a delimiter for line splitting.
If the string string ="someText~someValue:", then "~" will be a separator to split the string
Is there a way to find out which delimiter was used and store in a variable.
PS: someText and someValue may contain special characters that are not used in split. For example: some-Text, some_Text, some $ Text
source
share