From 2e379710ca4ca1739788beb502a55d8bd596dc16 Mon Sep 17 00:00:00 2001 From: Jonas Maier Date: Sat, 6 Jun 2026 22:55:27 +0200 Subject: regex: submatches now go into variables --- src/run/mod.rs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'src/run') diff --git a/src/run/mod.rs b/src/run/mod.rs index 64522d9..3420c30 100644 --- a/src/run/mod.rs +++ b/src/run/mod.rs @@ -457,10 +457,17 @@ impl Executor { stdout: OutputWriter, ) -> SpawnedCmd { for branch in c.branches.into_iter() { - // TODO: do not compile every time - if let Ok(compiled) = branch.pattern.try_compile() - && compiled.matches(&c.discriminant) + if let Ok(compiled) = Session::cached_regex(self.se.as_ref(), branch.pattern) + && let Some(mtch) = compiled.run(&c.discriminant) { + // put submatches into variables + if !mtch.submatches.is_empty() { + let mut se = self.se.lock().unwrap(); + for (var, match_loc) in mtch.submatches.into_iter() { + let val = c.discriminant[match_loc].to_vec(); + se.vars.set(var, val); + } + } return self.execute_block(branch.block, stdin, stdout); } } -- cgit v1.2.3