Expand description
Find all binaries matching a regular expression in a the system PATH.
Only available when feature regex
is enabled.
Arguments
regex
- A regular expression to match binaries with
Examples
Find Python executables:
use regex::Regex;
use which::which;
use std::path::PathBuf;
let re = Regex::new(r"python\d$").unwrap();
let binaries: Vec<PathBuf> = which::which_re(re).unwrap().collect();
let python_paths = vec![PathBuf::from("/usr/bin/python2"), PathBuf::from("/usr/bin/python3")];
assert_eq!(binaries, python_paths);
Find all cargo subcommand executables on the path:
use which::which_re;
use regex::Regex;
which_re(Regex::new("^cargo-.*").unwrap()).unwrap()
.for_each(|pth| println!("{}", pth.to_string_lossy()));