Cleaner version of implementation using same regex to ahndle -f or -r