diff --git a/rust/hg-core/src/filepatterns.rs b/rust/hg-core/src/filepatterns.rs
--- a/rust/hg-core/src/filepatterns.rs
+++ b/rust/hg-core/src/filepatterns.rs
@@ -171,6 +171,10 @@ pub fn parse_pattern_syntax(
     }
 }
 
+lazy_static! {
+    static ref FLAG_RE: Regex = Regex::new(r"^\(\?[aiLmsux]+\)").unwrap();
+}
+
 /// Builds the regex that corresponds to the given pattern.
 /// If within a `syntax: regexp` context, returns the pattern,
 /// otherwise, returns the corresponding regex.
@@ -193,7 +197,22 @@ fn _build_single_regex(entry: &IgnorePat
             {
                 return pattern.to_owned();
             }
-            [&b".*"[..], pattern].concat()
+            match FLAG_RE.find(pattern) {
+                Some(mat) => {
+                    let s = mat.start();
+                    let e = mat.end();
+                    [
+                        &b"(?"[..],
+                        &pattern[s + 2..e - 1],
+                        &b":"[..],
+                        &b".*"[..],
+                        &pattern[e..],
+                        &b")"[..],
+                    ]
+                    .concat()
+                }
+                None => [&b".*"[..], pattern].concat(),
+            }
         }
         PatternSyntax::Path | PatternSyntax::RelPath => {
             if pattern == b"." {
@@ -703,4 +722,35 @@ mod tests {
             Some(br"[^/]*\.o(?:/|$)".to_vec()),
         );
     }
+
+    #[test]
+    fn test_build_single_relregex() {
+        assert_eq!(
+            build_single_regex(&IgnorePattern::new(
+                PatternSyntax::RelRegexp,
+                b"^ba{2}r",
+                Path::new("")
+            ))
+            .unwrap(),
+            Some(b"^ba{2}r".to_vec()),
+        );
+        assert_eq!(
+            build_single_regex(&IgnorePattern::new(
+                PatternSyntax::RelRegexp,
+                b"ba{2}r",
+                Path::new("")
+            ))
+            .unwrap(),
+            Some(b".*ba{2}r".to_vec()),
+        );
+        assert_eq!(
+            build_single_regex(&IgnorePattern::new(
+                PatternSyntax::RelRegexp,
+                b"(?ia)ba{2}r",
+                Path::new("")
+            ))
+            .unwrap(),
+            Some(b"(?ia:.*ba{2}r)".to_vec()),
+        );
+    }
 }
diff --git a/tests/test-hgignore.t b/tests/test-hgignore.t
--- a/tests/test-hgignore.t
+++ b/tests/test-hgignore.t
@@ -90,8 +90,7 @@ flag in a pattern should affect that pat
   $ echo 're:.HGIGNORE' >> .hgignore
   $ hg status
   A dir/b.o
-  ? .hgignore (no-rust !)
-  ? .hgignore (rust missing-correct-output !)
+  ? .hgignore
   ? a.c
   ? syntax