var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: RegExp Pattern for a Tag Column
I have a column named Tags of varchar type which hold tags separated by commas.
Example of a possible field value for Tags: bikes, road trip, summer
will obviously select the example row but it shouldn't since it doesn't come under
SELECT * FROM `tablename` WHERE `Tags` LIKE '%road%'
road but under road trip.
Using PHP's preg_match is easy but in this case I need a SQL solution.
How do I go abt making the condition for the query using the Regexp ? (^|,\s*)road(\s*,|$)
Now I got this to work and it doesnt select the road trip row for road, but neither does it get selected for road trip
Any idea what I might be dong wrong here ?
make sure there are no extraneous spaces around your commas, and then do this:
... WHERE CONCAT(',',Tags,',') LIKE '%,road,%'
Nice workaround, but having to change the current set of data to get trim whitespaces surrounding the commas is not viable.
Anyway, MySQL doesnt seem to recognize \s - I just replaced it with a whitespace and it worked !
(^|, *)road trip( *,|$)
well, if every comma is consistently followed by a space, then you can simply do it like this --
see the difference?
... WHERE CONCAT(', ',Tags,', ') LIKE '%, road, %'
Problem is, the tag information was entered by users via an html form (were told to separate tags by a comma) which is still online and I just can't rely on the data entered by them. Obviously, the back-end script would be modified to strip spaces surrounding commas, but for the existing data, I'll need to assume any number of spaces surrounding a comma.