Regex to find a number inside divs

Any questions involving matching text strings to patterns - the pattern is called a "regular expression."

Moderator: General Moderators

Post Reply
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Regex to find a number inside divs

Post by klevis miho »

I have this regular exrpression:

'#<div>(.+?)</div>#s'

which gets everything inside a div pair.

I want to get just the number inside this div's.
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Regex to find a number inside divs

Post by ridgerunner »

what number?
klevis miho
Forum Contributor
Posts: 413
Joined: Wed Oct 29, 2008 2:59 pm
Location: Albania
Contact:

Re: Regex to find a number inside divs

Post by klevis miho »

any number
User avatar
ridgerunner
Forum Contributor
Posts: 214
Joined: Sun Jul 05, 2009 10:39 pm
Location: SLC, UT

Re: Regex to find a number inside divs

Post by ridgerunner »

This one will find the first multi-digit integer following an opening div before a closing div, and capture that number into group 1:

Code: Select all

$re = '%<div>(?:(?!</div>|\d).)*(\d+)%s';
Post Reply