R
Ryan Wallace
I am trying to split a string on all occurrences of ' AND ' except
where it appears within quotes. I have a regular expression which
works but generates strange output in a certain case:
"text_search '(large red spear OR axe) AND wood' AND material
1".split( /(?: AND )?(\S+ '.+')(?: AND )?|(?: AND )/ )
gives:
["", "text_search '(large red spear OR axe) AND wood'", "material 1"]
I don't understand why my regular expression is producing the blank
entry at the beginning of the array. Can anyone lend some insight?
Thanks,
Ryan Wallace
where it appears within quotes. I have a regular expression which
works but generates strange output in a certain case:
"text_search '(large red spear OR axe) AND wood' AND material
1".split( /(?: AND )?(\S+ '.+')(?: AND )?|(?: AND )/ )
gives:
["", "text_search '(large red spear OR axe) AND wood'", "material 1"]
I don't understand why my regular expression is producing the blank
entry at the beginning of the array. Can anyone lend some insight?
Thanks,
Ryan Wallace