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