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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -