I'm having quite a time with this particular problem:
I have users that enter tag words as form input, let's say for a photo or a topic of discussion. They are allowed to delimit tags with spaces and commas, and can use quotes to encapsulate multiple words.
An example:
tag1, tag2 tag3, "tag4 tag4, tag4" tag5, "tag6 tag6"
So, as we can see here anything is allowed, but the problem is that splitting on commas obviously destroys tag4 (the tag inside quotes but with a comma).
I've tried tons of regex, using preg_split, preg_match, and more but cannot figure out a solution. If this cannot be done, then it's also completely okay to tell the user they are not allowed to use commas inside of quoted strings via error message - which I tried doing using preg_match but my regex fails.
My regex for preg_match to alert the user of the problem:
/".*,.*"/
This works fine, but if you put any other quotes after the first quoted string (referring to "tag6 tag6") then it fails when it should not, since there are no commas inside tag6.
I have users that enter tag words as form input, let's say for a photo or a topic of discussion. They are allowed to delimit tags with spaces and commas, and can use quotes to encapsulate multiple words.
An example:
tag1, tag2 tag3, "tag4 tag4, tag4" tag5, "tag6 tag6"
So, as we can see here anything is allowed, but the problem is that splitting on commas obviously destroys tag4 (the tag inside quotes but with a comma).
I've tried tons of regex, using preg_split, preg_match, and more but cannot figure out a solution. If this cannot be done, then it's also completely okay to tell the user they are not allowed to use commas inside of quoted strings via error message - which I tried doing using preg_match but my regex fails.
My regex for preg_match to alert the user of the problem:
/".*,.*"/
This works fine, but if you put any other quotes after the first quoted string (referring to "tag6 tag6") then it fails when it should not, since there are no commas inside tag6.
Comment