Well, it seems to me that you don't need OR conditions at all (but see below).
For a numeric bit, you can leave with:
\d+(\s+\d+/\d+)
which would handle all these fractional values.
I would still keep your decimal separator with the OR clause, as it can complicate things. Therefore, I think you could leave with something like:
^\s*((\d+\s)?(\d+/\d+)?|\d+(\.\d+)?)\s*([az].*)?$ | | | | | | | | | +--- start of alpha section. | | | +------ optional white space. | | +------------------ decimal (nn[.nn]) | +------------------------------------- fractional ([nn ][nn/nn]) +----------------------------------------- optional starting space.
although this allows an empty fractional sum, so you might be better off with what you have (integer, fractional, and decimal in separate OR sentences).
I prefer the ([az].*)?$ Construct to ($|[az].*)$ On my own, but it may just be a disgust to my past to have multiple end-of-line markers in my RE :-)
But to be honest, I think you are probably trying to lure a fly with a thermonuclear warhead here.
You really need to limit your input. I saw recipes calling a pinch of salt and a handful of sultanas . I personally believe that you can limit yourself to what you allow. I would have a free form field for the quantity and a drop-down list for the type of food (in fact, I would probably just allow a free form for the party if I did not offer the possibility of finding recipes based on what's in the fridge).
paxdiablo
source share