elaineee elaineee - 1 year ago 85
PHP Question

PHP custom regex in url

I am new in Stackoverflow and I have a simple question: I need to create a regex to match a custom patterns in string. I want to create a regex to detect this url:


where $match[0] = 92581 and $match[1] = 1

I created this regex
works fine,but this returns:

$match[0] // -92581
$match[1] // 1

if i change string to
i get

$match[0] // -81
$match[1] // 1

I only want to get the FIRST MATCH
without "

Answer Source

Put the - outside of the brackets...


Everything inside the brackets gets returned as a match!

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download