You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inline flags such as (?i) in one -e pattern leak into the other patterns, and indexed and scanned results disagree #182
When several patterns are given with -e (or -f), an inline flag group such as (?i) or (?-i) at the start of one pattern also applies to the patterns after it. ripgrep scopes inline flags to the pattern they appear in.
The index planner parses each pattern on its own, so it and the matcher disagree: the same query can give different results with and without the index.
In the first query, (?-i) from foo turns -i off for BAR too, so bar is missed everywhere.
In the second, (?i) from foo makes BAR match bar during a scan. The index planned BAR case-sensitively and drops the file, so the indexed result differs from the scan.
With -w or -x the queries behave like ripgrep, because each pattern is then wrapped in its own group.
Environment
tgrep 1.1.0, built from 1120aca (current main) with rustc 1.95.0 (59807616e 2026-04-14)
Windows 11 Pro (build 28000); the code involved is platform-independent
The indexed result is the same with a local index and through tgrep serve
Cause
combine_patterns only wraps a pattern in a group for -w/-x. Otherwise it joins the raw patterns as alternatives of one group:
let parts:Vec<String> = patterns.iter().map(wrap).collect();
format!("(?:{})", parts.join("|"))
}
-e '(?i)foo' -e 'BAR' becomes (?:(?i)foo|BAR). In regex syntax a bare flag group applies until the end of the enclosing group, so it reaches BAR too. build_multi_pattern_plan plans each pattern separately, where the flag does not leak.
Possible fix
Wrap every pattern in its own non-capturing group before joining, for example (?:(?i)foo)|(?:BAR), whether or not -w/-x is set. Flags then stay inside their pattern, which is also how the planner already reads them. The fancy-regex path is built from the same combined string, so it would be covered too.
A regression test could compare both queries above across --no-index, a local index and serve.
Activity
Fix search compatibility bugs and Linux RSS test (microsoft#187)