I would like to split the next line with the word “and”, unless the word “and” is in quotation marks
string = "section_category_name = 'computer and equipment expense' and date >= 2015-01-01 and date <= 2015-03-31"
Desired Result
["section_category_name = 'computer and equipment expense'","date >= 2015-01-01","date <= 2015-03-31"]
I can’t find the correct regex pattern that correctly separates the string, so that “computer and hardware costs” are not shared.
Here is what I tried:
re.split('and',string)
Result
[" section_category_name = 'computer "," equipment expense' ",' date >= 2015-01-01 ',' date <= 2015-03-31']
As you can see, the result broke the "consumption of computers and equipment" into different elements in the list.
I also tried the following from this question :
r = re.compile('(?! )[^[]+?(?= *\[)'
'|'
'\[.+?\]')
r.findall(s)
Result:
[]
I also tried the following from question
result = re.split(r"and+(?=[^()]*(?:\(|$))", string)
Result:
[" section_category_name = 'computer ",
" equipment expense' ",
' date >= 2015-01-01 ',
' date <= 2015-03-31']
, , .
,
string = " section_category_name = (computer and equipment expense) and date >= 2015-01-01 and date <= 2015-03-31"
result = re.split(r"and+(?=[^()]*(?:\(|$))", string)
[' section_category_name = (computer and equipment expense) ',
' date >= 2015-01-01 ',
' date <= 2015-03-31']
, ''