Skip to content
Advertisement

Splitting string that’s really an array?

I’m trying to split this string var raw = "GMYTEOR[RHE5DO,SG[A5D[CN[I,Q],EM[I,Q],M],E5D[C[NY,OA],O,Q],M5DC[MY,NA],U5DQ,Y5DCOA]]"

I manually split this out into the following patterns:

JavaScript

I tried parsing it with JSON.parse but that didnt work for obvious reasons.

I also tried splitting the string by the brackets but that was a really bad idea and I couldn’t get it working after 20-30 mins of trying.

What’s the best way to convert that bizarre string format into a formatted array as shown in valid_results?

Advertisement

Answer

This should work:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement