0

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

2 Answers 2

1

Though I don't really understand the question, your regex would be

\?([^=]+)=([^&]*)
\?         # a literal question mark
(          # group 1
  [^=]+    # anything but a "=", 1-unlimited chars
)          # end group 1
=          # the "="
(          # group 2
  [^&]*    # anything but a "&", 0-unlimited chars
)          # end group 2

Can you explain what you are actually trying to do?

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

Comments

0

How about:-

(\?)([^=]+)(=)(.+)

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.