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

timeout - Handshake_timeout on RabbitMQ using python and pika from remote vm -

gcc - MinGW's ld cannot perform PE operations on non PE output file -

c# - Search and Add Comment with OpenXML for Word -