regex - python - How to know what re used to split a string? -
the code below lets user input 2 names of movies separated either &
, |
or ^
:
query = raw_input("enter query:") movie_f = re.split('&|\^|\|', query)[0].strip() movie_s = re.split('&|\^|\|', query)[1].strip()
i want know re
has used separate string (&
, |
or ^
). how can that?
if group regex return items split every second item.
>>> query '&foo^bar' >>> re.split(r'(&|\^|)', query) ['', '&', 'foo', '^', 'bar']
Comments
Post a Comment