PDA

View Full Version : IMPORTANT: can you split with a regex?


BrightNail
04-17-2003, 10:20 PM
hey,

you know how the split function works...

somestring.split(":")

we are breaking on the :

Now, I have a string that can have numerous "commas" -, but I only want to split the ones that seperate the arrays...for instance.

"my car, is the coolest in the world","Operation mind crime"

each of those entires is an array within a larger array..multidimensional..it has to be this way.

now, I need to split on the comma ..unfortunetly this gives me the strings
my car
is the coolest in the world
operation mind crime

it splits on the comma in the array too?

how can I split on the comma that seperates the arrays?

I was thinking.

somestring.split("\",\"")

beetle
04-17-2003, 10:58 PM
split() is for exploding a string into an array. But the way you describe it, it sounds like you already have arrays.

I mean,

"my car, is the coolest in the world","Operation mind crime"

is an invalid string, but

"\"my car, is the coolest in the world\",\"Operation mind crime\""

would be correct. Is this what you have? If so

someString.split( /\,(?=")/g )