Page 1 of 1

A way to escape a comma?

Posted: Fri Oct 19, 2007 12:10 am
by yanisdon
Hi there,
Just a quick q:

Is there a way to escape a comma- possibly with a fancy regex or something?

Cheers

Posted: Fri Oct 19, 2007 12:11 am
by aaronhall
Escape a comma in what context..?

Posted: Fri Oct 19, 2007 12:21 am
by yanisdon
A little bit of background-info:
I wrote a little app using Magpie to parse a RSS/XML file into an array.
One field of that array is getting filled with 'taxonomy terms'. Sometime those terms are containing comma's (E.g. "Folksonomy, multiple Taxonomies combined"). Alas my app doesn't like that programmatically wise, because I am using a function to comma-separate terms :)

This unfortunately will render the term in question into the two new terms: "Folksonomy" and "multiple Taxonomies combined".

Cheers.

Posted: Fri Oct 19, 2007 12:26 am
by John Cartwright
Normally when the character used as a delimeter is found within the string, the string is wrapped in quotes.

Check out the user comments on how to parse csv strings

Posted: Fri Oct 19, 2007 12:26 am
by Josh1billion
Hmm.. strange idea I have but what if you do a backwards escape? I.e., instead of using "," as the glue holding your string pieces together, why not use "\," (or some other rarely-typed string) as the parsing glue? Then you'll only run into problems if the user decides to type "\," into field.

Posted: Fri Oct 19, 2007 12:38 am
by Kieran Huggins
I would first consider changing my delimiter to something less common then a comma, like [--delimiter--]

What are the chances anyone would tag something that?

@aaronhall: I just got your avatar... priceless!

Posted: Fri Oct 19, 2007 12:59 am
by yanisdon
Yeah, actually that's pretty close to what I was thinking as well.

However, is there a way to escape a comma?

There must be some creepy regex out there. Am stoked to learn about that..

Posted: Fri Oct 19, 2007 2:23 am
by Josh1billion
Kieran Huggins wrote:I would first consider changing my delimiter to something less common then a comma, like [--delimiter--]
That's what I meant.. ;)