-1
80 x 59 x 53 108 x 98 x 73

I want to split this string into

80 x 59 x 53 and 108 x 98 x 73

There could be any number of spaces in between any characters

Please help me to solve this

Thanks in Advance

Anoop
  • 2,748
  • 4
  • 18
  • 27

1 Answers1

0

Use positive lookbehind and positive lookahead regex:

import re

s = '80 x 59 x 53 108 x 98 x 73'
print(re.split(r'(?<=\d)\s+(?=\d)', s))

# ['80 x 59 x 53', '108 x 98 x 73']

If you're concerned about and in-between:

print(' and '.join(re.split(r'(?<=\d)\s+(?=\d)', s)))

# 80 x 59 x 53 and 108 x 98 x 73
Austin
  • 25,759
  • 4
  • 25
  • 48