Hey, all. Need some help here.
I have a working PHP script to convert a fraction to a decimal using a
regular expression. The PHP works, but the regex is broken somehow.
Here's what I have:
([0-9]+)?[[:space:]]?(([0-9]+)/([0-9]+))?
The PHP extrapolates this into a base variable, numerator, and
denominator.
So it works if I have 1 1/2, or 2/3. But if I have something like
50/200, it assumes that I mean 5 0/200. I get why it's doing that. I
have a ? next to the space. I've tried doing (([0-9]+)?[[:space:]])?
but that breaks the whole thing and gives me 1's and 0's. Am I on the
right track, here?
I am just not a regexpert, so I need a little push in the right
direction.
Thanks for your time!