Click to See Complete Forum and Search --> : Splitting String, Regex


crazycoder
09-17-2008, 08:24 PM
Anyone have a good way to do this:

I need to split a string that looks something like this:

Text text text {1:more text} Some more text {2:hi} blah blah {$1} blah {$2} o and also {3} blah blah

into an array that ends up looking like this:

["Text text text ", "{1:more text}", " Some more text ", "{2:hi}", " blah blah ", "{$1}", " blah ", "{$2}", " o and also ", "{3}", " blah blah"]

chazzy
09-17-2008, 08:48 PM
maybe
((.+){.+})* ? just a wild guess mostly. it won't give you that exact array either, but you should be pretty close.

i guess using the java standard {0} doesn't do it, huh?

crazycoder
09-19-2008, 05:03 PM
Thanks that was very helpful. The splitting string I'm actually using is this one now "\\{[^\\{\\}]+\\}". But this split removes all of the instances that I also want in the array. Does anyone have a great way of doing that?