Regular Expression for $_GET query strings
Posted
by sandelius
on Stack Overflow
See other posts from Stack Overflow
or by sandelius
Published on 2010-04-16T17:18:25Z
Indexed on
2010/04/16
17:23 UTC
Read the original article
Hit count: 269
Hi there!
I'm trying to find a regular expression for $_GET
query strings.
I have an array like this:
private $_regexp = array(
':id' => '[0-9]+',
':year' => '[12][0-9]{3}',
':month' => '0[1-9]|1[012]',
':day' => '0[1-9]|[12][0-9]|3[01]',
':slug' => '[a-zA-Z0-9-]+',
':query' => '...'
);
and I loop throw them to see if I have a matching wildcard like this:
if ( array_key_exists($matches[0], $this->_regexp) )
{
return '^('.$this->_regexp[$matches[0]].')$';
}
All other regexp go throw but I've tried a whole lot of different regexp to find:
?anything=anything
can't figure it out, googled like h..l but can't find anything. I've tried, for example something like this:
(\?)(.*)(=)(.*)
but without result...
Any regexp gurus here?
/ Tobias
© Stack Overflow or respective owner