1
case1 = """ do some test
here"""
case2 = """ do some test2
here"""

print(case1.split("some")[1].split('\n|,')[0])

neither \n nor , are working here.

output should be

 test

but its giving me

 test,
here
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555

1 Answers1

0

Apparently you want to split with a regex expression. But that is not how str.split(..) works: it splits by a string.

We can use the re module to split correctly:

import re

print(re.split('\n|,', case1.split("some")[1])[0])

This produces:

>>> print(re.split('\n|,', case1.split("some")[1])[0])
 test
>>>
Willem Van Onsem
  • 443,496
  • 30
  • 428
  • 555