php - regex item count -


i have 2 distinct styles of item count text extract total number of items from.

from style 1 need number 3, style 2 need 56

style 1: 3 item(s)  style 2: items 1 45 of 56 total 

i trying match

/(?<page>\d+,?\d+) total| item\(s\)/ 

it matches 56 in style 2 not 3 in style 1.

this used preg_match in php ( can't change feeding values via webform )

i have other regex's i've tried, post if required.

you need put total, item inside capturing or non-capturing group, first pattern become common 1 both total , item.

(?<page>\d+(?:,\d+)*)(?: total| item\(s\)) 

demo


Comments

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

jdbc - Not able to establish database connection in eclipse -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -