@@ -22,6 +22,7 @@ pub struct RegexOptions {
2222 pub swap_greed : bool ,
2323 pub ignore_whitespace : bool ,
2424 pub unicode : bool ,
25+ pub octal : bool ,
2526}
2627
2728impl Default for RegexOptions {
@@ -37,6 +38,7 @@ impl Default for RegexOptions {
3738 swap_greed : false ,
3839 ignore_whitespace : false ,
3940 unicode : true ,
41+ octal : false ,
4042 }
4143 }
4244}
@@ -142,6 +144,26 @@ impl RegexBuilder {
142144 self
143145 }
144146
147+ /// Whether to support octal syntax or not.
148+ ///
149+ /// Octal syntax is a little-known way of uttering Unicode codepoints in
150+ /// a regular expression. For example, `a`, `\x61`, `\u0061` and
151+ /// `\141` are all equivalent regular expressions, where the last example
152+ /// shows octal syntax.
153+ ///
154+ /// While supporting octal syntax isn't in and of itself a problem, it does
155+ /// make good error messages harder. That is, in PCRE based regex engines,
156+ /// syntax like `\0` invokes a backreference, which is explicitly
157+ /// unsupported in Rust's regex engine. However, many users expect it to
158+ /// be supported. Therefore, when octal support is disabled, the error
159+ /// message will explicitly mention that backreferences aren't supported.
160+ ///
161+ /// Octal syntax is disabled by default.
162+ pub fn octal( & mut self , yes: bool ) -> & mut RegexBuilder {
163+ self . 0 . octal = yes;
164+ self
165+ }
166+
145167 /// Set the approximate size limit of the compiled regular expression.
146168 ///
147169 /// This roughly corresponds to the number of bytes occupied by a single
@@ -283,6 +305,26 @@ impl RegexSetBuilder {
283305 self
284306 }
285307
308+ /// Whether to support octal syntax or not.
309+ ///
310+ /// Octal syntax is a little-known way of uttering Unicode codepoints in
311+ /// a regular expression. For example, `a`, `\x61`, `\u0061` and
312+ /// `\141` are all equivalent regular expressions, where the last example
313+ /// shows octal syntax.
314+ ///
315+ /// While supporting octal syntax isn't in and of itself a problem, it does
316+ /// make good error messages harder. That is, in PCRE based regex engines,
317+ /// syntax like `\0` invokes a backreference, which is explicitly
318+ /// unsupported in Rust's regex engine. However, many users expect it to
319+ /// be supported. Therefore, when octal support is disabled, the error
320+ /// message will explicitly mention that backreferences aren't supported.
321+ ///
322+ /// Octal syntax is disabled by default.
323+ pub fn octal( & mut self , yes: bool ) -> & mut RegexSetBuilder {
324+ self . 0 . octal = yes;
325+ self
326+ }
327+
286328 /// Set the approximate size limit of the compiled regular expression.
287329 ///
288330 /// This roughly corresponds to the number of bytes occupied by a single
0 commit comments