Reputation: 9653
The code below lets a user input two names of movies separated by either &
, |
or ^
:
query = raw_input("Enter your query:")
movie_f = re.split('&|\^|\|', query)[0].strip()
movie_s = re.split('&|\^|\|', query)[1].strip()
I want to know what re
has used to separate the string (&
, |
or ^
). How can i do that?
Upvotes: 1
Views: 81
Reputation: 133634
If you group the regex it will return the items it split by for every second item.
>>> query
'&foo^bar'
>>> re.split(r'(&|\^|)', query)
['', '&', 'foo', '^', 'bar']
Upvotes: 3