Reputation: 236
I have two distinct styles of item count text to extract the total number of items from.
From style 1 I need the number 3, From Style 2 i need 56
Style 1:
3 Item(s)
Style 2:
Items 1 to 45 of 56 total
I was trying this to match
/(?<page>\d+,?\d+) total| Item\(s\)/
It matches the 56 in style 2 but not the 3 in style 1.
This will be used with preg_match in php ( we can't change that as we are feeding values via a webform )
I have some other regex's I've tried, which I could post if required.
Upvotes: 1
Views: 204
Reputation: 174706
You need to put total
, item
inside a capturing or non-capturing group, so that the first pattern would become a common one for both total
and Item
.
(?<page>\d+(?:,\d+)*)(?: total| Item\(s\))
Upvotes: 1