Track Topic
: rss

Topic: regexes for parsing compressed strings

posts 1–5 of 5
Page 1
?
13 posts

Here's one for splitting the markets from GetAllMarkets api:
(?<!\):

or
"(?<!\\):" if you want it in java.

(?<!\) is a lookback to not split based on \:

?
13 posts

the web page removed half the slashes
so once more:

(?<!\\):

"(?<!\\\\):" if you want it in java.

?
73 posts
Just had a bit of a break from stuff, needed to rethink how I was doing the mechanics of my little bot and just used this little snippet to decompress GMPC.

Using the Java version you wrote and it works like a dream. Have no idea what it is saying (except I know you need four backslashes in order to escape one in Java) but the rest of it has me boggled. If you fancy explaining it, I - and probably a few others who are unfamiliar with regexes - would greatly appreciate it. If not, then I will have to put it on the list of Things I Need To Understand and work it out myself. In any case, thanks heaps.

__________________
Slashdot. It's like Digg on slow, but sensible.
?
13 posts

ahh... called my bluff. Can't say I'm any kind of regex expert. I know they are useful and can be a very fast way of parsing strings. I generally arrive at the right combination of squiggles more through trial and error than any kind of intelligent design.

This one is made of two parts. The requirement is to split the markets string on the ":" character, except where it has been prefixed with a backslash indicating it has been escaped. You find this sometimes in times or other uses of the ":". So the part in brackets is (with enough slashes to convince the java compiler) known as a "Zero-width negative lookbehind", for a single backslash in this case. This ensures a match is only made if the ":" doesn't have a slash before it. See http://www.regular-expressions.info/refadv.html for a more accurate description.

member
73 posts
Outstanding - regexes really are something I keep reminding myself I have to learn, but never seem to get around to. I think when I have finished my cisco course in October, I have until the next january with no study happening. I might sit myself down and get my head around it then.

Thanks again.

__________________
Slashdot. It's like Digg on slow, but sensible.
posts 1–5 of 5
Page 1

This Topic Is Locked To Guest Posts

It's been a while since this topic was active, if you'd like to get it going again, please post as a registered member

join now