I've looked everywhere but no solution seems to work for this problem. Say I've been given a String with text like this:
jx():{ww.}55<<;<5<>=-[]+*/"hrw 7 n t";fizz buzz
And I want to split this String into an array so it looks like this (the commas signifying different array positions:
"jx","(",")",":","{","ww",".","}","55","<<",";","<","5","<",">","=","-","[","]","+","*","/","hrw 7 n t",";","fizz","buzz"
This was my Regular Expression, I used the ?= to keep the delimiters or whatever you want to call them and whenever I did, while it did keep the delimiters, it did not split on the delimiters if another character was directly after it, or just sometimes at all, I looked at other solutions and all that I had tried gave me the same result:
str=str.split(/(?=".*")|(?=[(){}\[\]<>:;.\=\-\*\+\/])|(?=\s{2,})|(?=[0-9]+)/)
And if I put the text above through the regular expression I get:
["jx", "(", ")", ":", "{ww", ".", "}", "5", "5", "<", "<", ";", "<", "5", "<", ">", "=", "-", "[", "]", "+", "*", "/", "\"hrw", " ", "7 n t\"", ";fizz buzz"]
As you can see, "ww" is in the same position as the } and at the end you can see that the semi-colon is in the same array position as fizz buzz which does not go into seperate positions.
The rule is as follows. Split on any whitespace but keep white spaces that are inbetween quotes. Split on {, }, (, ), %, <<, <,>,-,+,=,||,&&,!,?,:,;., or split on a quotation so that the entire text between the quotation will be one array position.
Edit: I believe I found the problem. It was that the regular expression was detecting words in between an ending and beginning quoatation as also in quotations. Example: "fizz" and "buzz" Technically and is between two quotations returning the value of " and " How do I solve this?
Any help is appreciated. Thanks!