Is there a MySQL equivalent of PHP's preg_replace?

Indeed, although I don't think there's a way to use the REGEXP function to do the replacement I'd need to do to work this select. Do you know how to structure that syntax? – Travis Nov 10 '09 at 4:28.

There is a library of user defined functions that gives you preg_replace in MySQL: mysqludf.org/lib_mysqludf_preg.

You might want to have a look at mysql pattern matching dev.mysql.com/doc/refman/5.1/en/pattern-....

I've found a solution. It's not ideal, but I'll put it in here in case a pure SQL solution never surfaces. I can leave the url field in MySQL equal to "/articles/%/page/%" and add another field called variables that stores a list of variable names to be used.

That way I can use my original query, then replace the "%" characters in the return value with "{{variable}}" in PHP with sprintf after I've retrieved the data. Still, I'd like to see this solved in SQL if possible, since I think the concept is valuable.

It sounds like what you want to do is have the new syntax in the database where the URLs have placeholders you would pass to your php-based (sprintf) variable replacement code, but still be able to do the original comparisons to match the URL. If I understand correctly you want to take a new URL format /article/{{slug}}/page/{{page_no}} and match it against something like /article/my-article/page/2 The preg plugin sagi mentioned can do the substitution you need, which will turn one of your newly formatted URLs into the original format you used to determine the match using the LIKE syntax. The following query: SELECT PREG_REPLACE('/({{.

*? }})/', '%', `url`) FROM urls; Would turn the new url (/article/{{slug}}/page/{{page_no}}) into what it was originally /article/%/page/% which can then be fed back through your original query, something like this: SELECT * FROM urls WHERE '/article/my-article/page/2' LIKE preg_replace('/({{. *?

}})/', '%', `url`); Some binary distributions like MAMP, XAMMP etc have the plugin already installed, but it isn't installed on a lot of systems like Macports / Ubuntu. Here are a couple of articles about installing the preg plugin. Hope it helps.

http://moxune.com/blog/2011/04/installing-mysql-preg-plugin-osx-macports/ http://moxune.com/blog/2011/12/installing-the-mysql-preg-plugin-on-ubuntu-with-apt-get.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions