I have a list of strings in a file. I am trying to extract a substring from each string and printing them. The strings look like the following -
Box1 is lifted\nInform the manufacturer
Box2 is lifted\nInform the manufacturer
Box3, Box4 is lifted\nInform the manufacturer
Box5, Box6 is lifted\nInform the manufacturer
Box7 is lifted\nInform the manufacturer
From each line I have to extract the string before \n
and print them. I used the following Python regex to do that - term = r'.*-\s([\w\s]+)\\n'
This regex works fine for the 1st, 2nd and last line. But it doesn't work for the 3rd and 4th lines since there is a ,
in the string. How should I modify my regex expression to fit in that?
Expected results -
Box1 is lifted
Box2 is lifted
Box3 Box4 is lifted
Box5 Box6 is lifted
Box7 is lifted
Results obtained currently -
Box1 is lifted
Box2 is lifted
Box2 is lifted
Box2 is lifted
Box7 is lifted