I’m trying to find a substring that looks like "3/4" (any number 0-9 for the numerator and denominator). However, the text that I am trying to parse may contain only a "/4" if its 1/4. In those cases, I don’t care about the "/" and only want the denominator. My current regular expression is "[0-9?\\/0-9]" but it returns '3/4' one by one, when I wanted it grouped instead.
Does anyone have a fix for this?
Thanks so much!
I think you want to use the pipe to create an or:
The downside of this approach though would be that you’d need to validate if group 1 or 2 returned a match… so if you had a full fraction you’d get a result in the first group, if you matched a denominator, the denominator would show up in the second group.
Might make more sense to:
And then check the length of each match back, and strip out the ‘/’ if you have to.