0

Within my MySQL table I have a row with this value for a column:

^[\/]?(Home|Index)\.php$

I would like to use this regex value during lookup rather than within my script.. I've looked around and found that MySQL IS capable of performing regex based queries, however I've only found resources which have the regex value within the query, not within table values..

I will admit that I could, very well, just be searching for the wrong information while I'm using search engines but I don't really know how to word this in a way that a search engine would understand..

I would greatly appreciate any information that could be supplied to me, even if that's only so much as a correct term to search for on Google..

Edit: Table structure:

CREATE TABLE IF NOT EXISTS `pages` (
`uid` int(12) NOT NULL,
  `title` varchar(70) NOT NULL,
  `href` text NOT NULL
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=2;

Single row of content:

INSERT INTO `pages` (`uid`, `title`, `href`) VALUES
(1, 'Home', '^[\\/]?(Home|Index)\\.htm[l]?$');

I made one attempt at actually obtaining a result, probably screwed up, but...

SELECT * FROM `pages` WHERE REGEXP `href`, '$_SERVER[REQUEST_URI]'

Although it's likely clear at this point, my processor is php.

3
  • You can use literal values or columns interchangeably in expressions. Show a query that you've tried or where you want to use it. And/or explain the table layout. Commented Sep 18, 2015 at 1:26
  • Updated, as per your specifications, @mario. Commented Sep 18, 2015 at 1:36
  • Worked like a charm, thanks. Please provide it as an answer so that I can accept it @chris85 Commented Sep 18, 2015 at 1:41

1 Answer 1

1

Your regexp expression syntax is incorrect. It should be

SELECT * FROM `pages` WHERE '$_SERVER[REQUEST_URI]' REGEXP `href`

Value REGEXP (as a keyword) then the expression.

https://dev.mysql.com/doc/refman/5.1/en/regexp.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.