-2

I have a string of the form

" This year is 2014"

I would like to split the string into two parts

part1="This year is"
part2="2014"
user3073498
  • 131
  • 2
  • 2
  • 5

1 Answers1

2

Split on whitespace followed by a digit, like this:

>>> part1, part2 = re.split(r'\s(?=\d)', " This year is 2014", 1)
>>> part1, part2
(' This year is', '2014')
RichieHindle
  • 272,464
  • 47
  • 358
  • 399