On 2015-06-04 06:36, Palpandi wrote: > This is the case. To split "string2" from "string1_string2" I am > using re.split('_', "string1_string2", 1)[1]. > > It is working fine for string "string1_string2" and output as > "string2". But actually the problem is that if a sting is > "__string1_string2" and the output is "_string1_string2". It is > wrong.
Why use regular expressions to split a string on a constant? Try for input in [ "string1_string2", "__string1_string2", ]: value = input.rsplit('_', 1)[-1] assert value == "string2" -tkc -- https://mail.python.org/mailman/listinfo/python-list