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
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
 
    
     
    
    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
>>>
