For example, I have a string :
/div1/div2[/div3[/div4]]/div5/div6[/div7]
Now I want to split the content by "/" and ignore the content in the "[ ]".
The result should be:
div1div2[/div3[/div4]]div5div6[/div7]How can I get the result using regular expression? My programming language is JavaScript.
You can't do this with regular expressions because it's recursive. (That answers your question, now to see if I can solve the problem elegantly...)
Edit: aem tipped me off! :D
Works as long as every [ is followed by /. It does not verify that the string is in the correct format.
string temp = text.Replace("[/", "[");
string[] elements = temp.Split('/').Select(element => element.Replace("[", "[/")).ToArray();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With