I have string looking like this:
'Toy Story..(II) (1995)'
I want to split the line into two parts like this:
['Toy Story..(II)','1995']
How can I do it? Thanks.
I have string looking like this:
'Toy Story..(II) (1995)'
I want to split the line into two parts like this:
['Toy Story..(II)','1995']
How can I do it? Thanks.
This code will get you started:
'Toy Stroy..(II) (1995)'.rstrip(')').rsplit('(',1)
Other than that, you can use r'\s*[(]\d{4}[)]\s*$' to match a four-digit number in parentheses at the end of the string. If you find it, you can chop it off:
s = ''
l = [s]
match = re.compile(r'\s*[(]\d+[)]\s*$').search(s)
if match is not None:
l = [s[:len(match.group(0))], s[-len(match.group(0)):].trim]
You could use regular expressions for that. See here: http://www.amk.ca/python/howto/regex/
Or you could use the split function and then manyally remove the parenthesis or other non desired characters. See here: http://www.python.org/doc/2.3/lib/module-string.html
l[:-1].split("(")