javascript – RegExp returning group matches
I am trying to make a regular expression to match quantities from a string using javascript
for example if I have "3-Ply Tissue, 23" x 24", 50/bg"
, I want to extract "50/bg"
. There can be multiple matches per string. Another stipulation is that the units on the bottom of the fraction can come from a list, for simplicity lets say I have "bg"
and "cs"
.
My regex is /\d+\/(bg|cs)/gi
When I execute the regular expression, this is what it returns.
> reg.exec(myString)
[
'50/bg',
'bg',
index: 25,
input: '3-Ply Tissue, 23" x 24", 50/bg',
groups: undefined
]
Why is it returning just "bg"
as a match? I think it must be something with my parentheses grouping, but I can’t figure it out and have tried many configurations.
Thanks in advance!
Read more here: Source link