22
How can I match irreducible fractions with regex?
For example, 23/25, 3/4, 5/2, 100/101, etc.
First of all, I have no idea about the gcd-algorithm realization in regex.
Update for all of you who's answering like "You are using the wrong tool":
Yeah, guys, I'm realizing what regex is normally used for. It's okay. But that this question is weird is kind of its whole point.
Updated 2: The idea is to find a regex that could be helpful in a situation like:
$> echo "1/2" | grep -P regex
1/2
$> echo "2/4" | grep -P regex
So, the regex should be only a string, without using any scripts and variables. Only regex.
Actually, I already know some regex which match reducible fractions written in the unary number system.
$> echo "11/1111" | grep -P '^1/1+$|(11+)+\1+/\1+$'
11/1111
So the thing is to convert from decimal to unary number system in regex, but I don't know how.