regex to match irreducible fractions

后端 未结 4 1005
野的像风
野的像风 2021-02-04 01:11

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

4条回答
  •  清酒与你
    2021-02-04 02:04

    If you write the numbers in unary, and use ":" as the division sign, I think this matches reducible fractions:

    /^1+:1$|^(11+):\1$|^(11+?)\2+:\2\2+$/
    

    You can then use !~ to find strings that don't match.

    Based on this: http://montreal.pm.org/tech/neil_kandalgaonkar.shtml

提交回复
热议问题