Skip to content

Commit

Permalink
change insert by regex to match the whole variable instead of just a …
Browse files Browse the repository at this point in the history
…substring

The regex is automatically extended with ^ and $ in order to anchor it to the
start and the end of the variable name.
Previously, a regex of just "bar" would match "foo_bar_baz", now ".*bar.*" is
needed for the same match.
  • Loading branch information
DanielT committed Sep 3, 2024
1 parent ea0fdf1 commit 63390a7
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,25 @@ pub(crate) fn insert_many<'param>(
};
// compile the regular expressions
for expr in measurement_regexes {
match Regex::new(expr) {
// extend the regex to match only the whole string, not just a substring
let extended_regex = if !expr.starts_with('^') && !expr.ends_with('$') {
format!("^{expr}$")
} else {
expr.to_string()
};
match Regex::new(&extended_regex) {
Ok(compiled_re) => isupp.compiled_meas_re.push(compiled_re),
Err(error) => println!("Invalid regex \"{expr}\": {error}"),
}
}
for expr in characteristic_regexes {
match Regex::new(expr) {
// extend the regex to match only the whole string, not just a substring
let extended_regex = if !expr.starts_with('^') && !expr.ends_with('$') {
format!("^{expr}$")
} else {
expr.to_string()
};
match Regex::new(&extended_regex) {
Ok(compiled_re) => isupp.compiled_char_re.push(compiled_re),
Err(error) => println!("Invalid regex \"{expr}\": {error}"),
}
Expand Down

0 comments on commit 63390a7

Please sign in to comment.