[Solved] Java int to fraction


Try (?<=-| |^)(\d+)(?!\d*\/)

Explanation:

(?<=...) – positive lookahead, assert, what precedes matches pattern inside

-| |^ – match either -, , or beginning of a line ^

(\d+) – match one or more digits and store in first capturing group

(?!\d*\/) – negative lookahead, assert what follows is not zero or mroe digits followed by \/.

Replace it with \1/1, so first capturing group followed by /1

Demo

1

solved Java int to fraction