Reputation: 2990
i have this string equation:
400-IF(3>5,5,5)+34+IF(4>5,5,6)
i want to split it by string 'IF(3>5,5,5)',
means 'IF()'
syntax, so here i used two if syntax.
so re.split()
should give list with length: 2 ['400-', '+34+']
I made re
and used as below.
re.split('IF[\(][0-9,a-z,A-Z,\$]*[\>|\<|=|/|%|*|^]?(.*)+[\,][0-9,a-z,A-Z,\$]*[\,][0-9,a-z,A-Z,\$]+[\)]', '400-IF(3>5,5,5)+34+IF(4>5,5,6)
')
But it is not returning proper answer. What is the mistake in my re
. I am new in re
.
Can anyone modify this re
in python?
Upvotes: 2
Views: 304
Reputation: 8709
>>> z = '400-IF(3>5,5,5)+34+IF(4>5,5,6)'
>>> ' '.join(re.split(r'IF\(.*?\)',z)).split()
['400-', '+34+']
Upvotes: 1
Reputation: 67968
x="400-IF(3>5,5,5)+34+IF(4>5,5,6)"
print [i for i in re.split(r"IF\([^)]*\)",x) if i]
You can simply use this.
Upvotes: 1