RegEx Question

Hello,

I’m working on a little pattern to parse a URL. Extracting all the needed data is working fine, however I’d like to tweak my pattern so that it doesn’t find a match at all when non-numerical data is present.

For example:

key25=10a12

My pattern finds: key25=10

But in these situations I don’t want the pattern to match. I want nothing. How do I do this?

The keys are in a URL separated by ampersands. Eg: key01=01&key02=02&key03=03 …

My pattern: code=([0-9]+)[/code]

Try this:

(key\\d+)=(\\d+)(?=&|$)

That uses a positive lookahead to confirm that the next character is either an ampersand or the end of the url.

It works perfectly. Thanks Kem.