2 This crate provides a library for parsing, compiling, and executing regular
3 expressions. Its syntax is similar to Perl-style regular expressions, but lacks
4 a few features like look around and backreferences. In exchange, all searches
5 execute in linear time with respect to the size of the regular expression and
8 This crate's documentation provides some simple examples, describes
9 [Unicode support](#unicode) and exhaustively lists the
10 [supported syntax](#syntax).
12 For more specific details on the API for regular expressions, please see the
13 documentation for the [`Regex`](struct.Regex.html) type.
17 This crate is [on crates.io](https://crates.io/crates/regex) and can be
18 used by adding `regex` to your dependencies in your project's `Cargo.toml`.
25 If you're using Rust 2015, then you'll also need to add it to your crate root:
31 # Example: find a date
33 General use of regular expressions in this package involves compiling an
34 expression and then using it to search, split or replace text. For example,
35 to confirm that some text resembles a date:
39 let re = Regex::new(r"^\d{4}-\d{2}-\d{2}$").unwrap();
40 assert!(re.is_match("2014-01-01"));
43 Notice the use of the `^` and `$` anchors. In this crate, every expression
44 is executed with an implicit `.*?` at the beginning and end, which allows
45 it to match anywhere in the text. Anchors can be used to ensure that the
46 full text matches an expression.
48 This example also demonstrates the utility of
49 [raw strings](https://doc.rust-lang.org/stable/reference/tokens.html#raw-string-literals)
51 are just like regular strings except they are prefixed with an `r` and do
52 not process any escape sequences. For example, `"\\d"` is the same
53 expression as `r"\d"`.
55 # Example: Avoid compiling the same regex in a loop
57 It is an anti-pattern to compile the same regular expression in a loop
58 since compilation is typically expensive. (It takes anywhere from a few
59 microseconds to a few **milliseconds** depending on the size of the
60 regex.) Not only is compilation itself expensive, but this also prevents
61 optimizations that reuse allocations internally to the matching engines.
63 In Rust, it can sometimes be a pain to pass regular expressions around if
64 they're used from inside a helper function. Instead, we recommend using the
65 [`lazy_static`](https://crates.io/crates/lazy_static) crate to ensure that
66 regular expressions are compiled exactly once.
71 #[macro_use] extern crate lazy_static;
76 fn some_helper_function(text: &str) -> bool {
78 static ref RE: Regex = Regex::new("...").unwrap();
86 Specifically, in this example, the regex will be compiled when it is used for
87 the first time. On subsequent uses, it will reuse the previous compilation.
89 # Example: iterating over capture groups
91 This crate provides convenient iterators for matching an expression
92 repeatedly against a search string to find successive non-overlapping
93 matches. For example, to find all dates in a string and be able to access
94 them by their component pieces:
97 # extern crate regex; use regex::Regex;
99 let re = Regex::new(r"(\d{4})-(\d{2})-(\d{2})").unwrap();
100 let text = "2012-03-14, 2013-01-01 and 2014-07-05";
101 for cap in re.captures_iter(text) {
102 println!("Month: {} Day: {} Year: {}", &cap[2], &cap[3], &cap[1]);
105 // Month: 03 Day: 14 Year: 2012
106 // Month: 01 Day: 01 Year: 2013
107 // Month: 07 Day: 05 Year: 2014
111 Notice that the year is in the capture group indexed at `1`. This is
112 because the *entire match* is stored in the capture group at index `0`.
114 # Example: replacement with named capture groups
116 Building on the previous example, perhaps we'd like to rearrange the date
117 formats. This can be done with text replacement. But to make the code
118 clearer, we can *name* our capture groups and use those names as variables
119 in our replacement text:
122 # extern crate regex; use regex::Regex;
124 let re = Regex::new(r"(?P<y>\d{4})-(?P<m>\d{2})-(?P<d>\d{2})").unwrap();
125 let before = "2012-03-14, 2013-01-01 and 2014-07-05";
126 let after = re.replace_all(before, "$m/$d/$y");
127 assert_eq!(after, "03/14/2012, 01/01/2013 and 07/05/2014");
131 The `replace` methods are actually polymorphic in the replacement, which
132 provides more flexibility than is seen here. (See the documentation for
133 `Regex::replace` for more details.)
135 Note that if your regex gets complicated, you can use the `x` flag to
136 enable insignificant whitespace mode, which also lets you write comments:
139 # extern crate regex; use regex::Regex;
141 let re = Regex::new(r"(?x)
142 (?P<y>\d{4}) # the year
144 (?P<m>\d{2}) # the month
146 (?P<d>\d{2}) # the day
148 let before = "2012-03-14, 2013-01-01 and 2014-07-05";
149 let after = re.replace_all(before, "$m/$d/$y");
150 assert_eq!(after, "03/14/2012, 01/01/2013 and 07/05/2014");
154 If you wish to match against whitespace in this mode, you can still use `\s`,
155 `\n`, `\t`, etc. For escaping a single space character, you can escape it
156 directly with `\ `, use its hex character code `\x20` or temporarily disable
157 the `x` flag, e.g., `(?-x: )`.
159 # Example: match multiple regular expressions simultaneously
161 This demonstrates how to use a `RegexSet` to match multiple (possibly
162 overlapping) regular expressions in a single scan of the search text:
167 let set = RegexSet::new(&[
177 // Iterate over and collect all of the matches.
178 let matches: Vec<_> = set.matches("foobar").into_iter().collect();
179 assert_eq!(matches, vec![0, 2, 3, 4, 6]);
181 // You can also test whether a particular regex matched:
182 let matches = set.matches("foobar");
183 assert!(!matches.matched(5));
184 assert!(matches.matched(6));
187 # Pay for what you use
189 With respect to searching text with a regular expression, there are three
190 questions that can be asked:
192 1. Does the text match this expression?
193 2. If so, where does it match?
194 3. Where did the capturing groups match?
196 Generally speaking, this crate could provide a function to answer only #3,
197 which would subsume #1 and #2 automatically. However, it can be significantly
198 more expensive to compute the location of capturing group matches, so it's best
199 not to do it if you don't need to.
201 Therefore, only use what you need. For example, don't use `find` if you
202 only need to test if an expression matches a string. (Use `is_match`
207 This implementation executes regular expressions **only** on valid UTF-8
208 while exposing match locations as byte indices into the search string. (To
209 relax this restriction, use the [`bytes`](bytes/index.html) sub-module.)
211 Only simple case folding is supported. Namely, when matching
212 case-insensitively, the characters are first mapped using the "simple" case
213 folding rules defined by Unicode.
215 Regular expressions themselves are **only** interpreted as a sequence of
216 Unicode scalar values. This means you can use Unicode characters directly
220 # extern crate regex; use regex::Regex;
222 let re = Regex::new(r"(?i)Δ+").unwrap();
223 let mat = re.find("ΔδΔ").unwrap();
224 assert_eq!((mat.start(), mat.end()), (0, 6));
228 Most features of the regular expressions in this crate are Unicode aware. Here
231 * `.` will match any valid UTF-8 encoded Unicode scalar value except for `\n`.
232 (To also match `\n`, enable the `s` flag, e.g., `(?s:.)`.)
233 * `\w`, `\d` and `\s` are Unicode aware. For example, `\s` will match all forms
234 of whitespace categorized by Unicode.
235 * `\b` matches a Unicode word boundary.
236 * Negated character classes like `[^a]` match all Unicode scalar values except
238 * `^` and `$` are **not** Unicode aware in multi-line mode. Namely, they only
239 recognize `\n` and not any of the other forms of line terminators defined
242 Unicode general categories, scripts, script extensions, ages and a smattering
243 of boolean properties are available as character classes. For example, you can
244 match a sequence of numerals, Greek or Cherokee letters:
247 # extern crate regex; use regex::Regex;
249 let re = Regex::new(r"[\pN\p{Greek}\p{Cherokee}]+").unwrap();
250 let mat = re.find("abcΔᎠβⅠᏴγδⅡxyz").unwrap();
251 assert_eq!((mat.start(), mat.end()), (3, 23));
255 For a more detailed breakdown of Unicode support with respect to
256 [UTS#18](https://unicode.org/reports/tr18/),
258 [UNICODE](https://github.com/rust-lang/regex/blob/master/UNICODE.md)
259 document in the root of the regex repository.
261 # Opt out of Unicode support
263 The `bytes` sub-module provides a `Regex` type that can be used to match
264 on `&[u8]`. By default, text is interpreted as UTF-8 just like it is with
265 the main `Regex` type. However, this behavior can be disabled by turning
266 off the `u` flag, even if doing so could result in matching invalid UTF-8.
267 For example, when the `u` flag is disabled, `.` will match any byte instead
268 of any Unicode scalar value.
270 Disabling the `u` flag is also possible with the standard `&str`-based `Regex`
271 type, but it is only allowed where the UTF-8 invariant is maintained. For
272 example, `(?-u:\w)` is an ASCII-only `\w` character class and is legal in an
273 `&str`-based `Regex`, but `(?-u:\xFF)` will attempt to match the raw byte
274 `\xFF`, which is invalid UTF-8 and therefore is illegal in `&str`-based
277 Finally, since Unicode support requires bundling large Unicode data
278 tables, this crate exposes knobs to disable the compilation of those
279 data tables, which can be useful for shrinking binary size and reducing
280 compilation times. For details on how to do that, see the section on [crate
281 features](#crate-features).
285 The syntax supported in this crate is documented below.
287 Note that the regular expression parser and abstract syntax are exposed in
288 a separate crate, [`regex-syntax`](https://docs.rs/regex-syntax).
290 ## Matching one character
293 . any character except new line (includes new line with s flag)
296 \pN One-letter name Unicode character class
297 \p{Greek} Unicode character class (general category or script)
298 \PN Negated one-letter name Unicode character class
299 \P{Greek} negated Unicode character class (general category or script)
302 ### Character classes
305 [xyz] A character class matching either x, y or z (union).
306 [^xyz] A character class matching any character except x, y and z.
307 [a-z] A character class matching any character in range a-z.
308 [[:alpha:]] ASCII character class ([A-Za-z])
309 [[:^alpha:]] Negated ASCII character class ([^A-Za-z])
310 [x[^xyz]] Nested/grouping character class (matching any character except y and z)
311 [a-y&&xyz] Intersection (matching x or y)
312 [0-9&&[^4]] Subtraction using intersection and negation (matching 0-9 except 4)
313 [0-9--4] Direct subtraction (matching 0-9 except 4)
314 [a-g~~b-h] Symmetric difference (matching `a` and `h` only)
315 [\[\]] Escaping in character classes (matching [ or ])
318 Any named character class may appear inside a bracketed `[...]` character
319 class. For example, `[\p{Greek}[:digit:]]` matches any Greek or ASCII
320 digit. `[\p{Greek}&&\pL]` matches Greek letters.
322 Precedence in character classes, from most binding to least:
324 1. Ranges: `a-cd` == `[a-c]d`
325 2. Union: `ab&&bc` == `[ab]&&[bc]`
326 3. Intersection: `^a-z&&b` == `^[a-z&&b]`
332 xy concatenation (x followed by y)
333 x|y alternation (x or y, prefer x)
339 x* zero or more of x (greedy)
340 x+ one or more of x (greedy)
341 x? zero or one of x (greedy)
342 x*? zero or more of x (ungreedy/lazy)
343 x+? one or more of x (ungreedy/lazy)
344 x?? zero or one of x (ungreedy/lazy)
345 x{n,m} at least n x and at most m x (greedy)
346 x{n,} at least n x (greedy)
348 x{n,m}? at least n x and at most m x (ungreedy/lazy)
349 x{n,}? at least n x (ungreedy/lazy)
356 ^ the beginning of text (or start-of-line with multi-line mode)
357 $ the end of text (or end-of-line with multi-line mode)
358 \A only the beginning of text (even with multi-line mode enabled)
359 \z only the end of text (even with multi-line mode enabled)
360 \b a Unicode word boundary (\w on one side and \W, \A, or \z on other)
361 \B not a Unicode word boundary
364 ## Grouping and flags
367 (exp) numbered capture group (indexed by opening parenthesis)
368 (?P<name>exp) named (also numbered) capture group (allowed chars: [_0-9a-zA-Z.\[\]])
369 (?:exp) non-capturing group
370 (?flags) set flags within current group
371 (?flags:exp) set flags for exp (non-capturing)
374 Flags are each a single character. For example, `(?x)` sets the flag `x`
375 and `(?-x)` clears the flag `x`. Multiple flags can be set or cleared at
376 the same time: `(?xy)` sets both the `x` and `y` flags and `(?x-y)` sets
377 the `x` flag and clears the `y` flag.
379 All flags are by default disabled unless stated otherwise. They are:
382 i case-insensitive: letters match both upper and lower case
383 m multi-line mode: ^ and $ match begin/end of line
384 s allow . to match \n
385 U swap the meaning of x* and x*?
386 u Unicode support (enabled by default)
387 x ignore whitespace and allow line comments (starting with `#`)
390 Flags can be toggled within a pattern. Here's an example that matches
391 case-insensitively for the first part but case-sensitively for the second part:
394 # extern crate regex; use regex::Regex;
396 let re = Regex::new(r"(?i)a+(?-i)b+").unwrap();
397 let cap = re.captures("AaAaAbbBBBb").unwrap();
398 assert_eq!(&cap[0], "AaAaAbb");
402 Notice that the `a+` matches either `a` or `A`, but the `b+` only matches
405 Multi-line mode means `^` and `$` no longer match just at the beginning/end of
406 the input, but at the beginning/end of lines:
410 let re = Regex::new(r"(?m)^line \d+").unwrap();
411 let m = re.find("line one\nline 2\n").unwrap();
412 assert_eq!(m.as_str(), "line 2");
415 Note that `^` matches after new lines, even at the end of input:
419 let re = Regex::new(r"(?m)^").unwrap();
420 let m = re.find_iter("test\n").last().unwrap();
421 assert_eq!((m.start(), m.end()), (5, 5));
424 Here is an example that uses an ASCII word boundary instead of a Unicode
428 # extern crate regex; use regex::Regex;
430 let re = Regex::new(r"(?-u:\b).+(?-u:\b)").unwrap();
431 let cap = re.captures("$$abc$$").unwrap();
432 assert_eq!(&cap[0], "abc");
439 \* literal *, works for any punctuation character: \.+*?()|[]{}^$
445 \v vertical tab (\x0B)
446 \123 octal character code (up to three digits) (when enabled)
447 \x7F hex character code (exactly two digits)
448 \x{10FFFF} any hex character code corresponding to a Unicode code point
449 \u007F hex character code (exactly four digits)
450 \u{7F} any hex character code corresponding to a Unicode code point
451 \U0000007F hex character code (exactly eight digits)
452 \U{7F} any hex character code corresponding to a Unicode code point
455 ## Perl character classes (Unicode friendly)
457 These classes are based on the definitions provided in
458 [UTS#18](https://www.unicode.org/reports/tr18/#Compatibility_Properties):
463 \s whitespace (\p{White_Space})
465 \w word character (\p{Alphabetic} + \p{M} + \d + \p{Pc} + \p{Join_Control})
466 \W not word character
469 ## ASCII character classes
472 [[:alnum:]] alphanumeric ([0-9A-Za-z])
473 [[:alpha:]] alphabetic ([A-Za-z])
474 [[:ascii:]] ASCII ([\x00-\x7F])
475 [[:blank:]] blank ([\t ])
476 [[:cntrl:]] control ([\x00-\x1F\x7F])
477 [[:digit:]] digits ([0-9])
478 [[:graph:]] graphical ([!-~])
479 [[:lower:]] lower case ([a-z])
480 [[:print:]] printable ([ -~])
481 [[:punct:]] punctuation ([!-/:-@\[-`{-~])
482 [[:space:]] whitespace ([\t\n\v\f\r ])
483 [[:upper:]] upper case ([A-Z])
484 [[:word:]] word characters ([0-9A-Za-z_])
485 [[:xdigit:]] hex digit ([0-9A-Fa-f])
490 By default, this crate tries pretty hard to make regex matching both as fast
491 as possible and as correct as it can be, within reason. This means that there
492 is a lot of code dedicated to performance, the handling of Unicode data and the
493 Unicode data itself. Overall, this leads to more dependencies, larger binaries
494 and longer compile times. This trade off may not be appropriate in all cases,
495 and indeed, even when all Unicode and performance features are disabled, one
496 is still left with a perfectly serviceable regex engine that will work well
499 This crate exposes a number of features for controlling that trade off. Some
500 of these features are strictly performance oriented, such that disabling them
501 won't result in a loss of functionality, but may result in worse performance.
502 Other features, such as the ones controlling the presence or absence of Unicode
503 data, can result in a loss of functionality. For example, if one disables the
504 `unicode-case` feature (described below), then compiling the regex `(?i)a`
505 will fail since Unicode case insensitivity is enabled by default. Instead,
506 callers must use `(?i-u)a` instead to disable Unicode case folding. Stated
507 differently, enabling or disabling any of the features below can only add or
508 subtract from the total set of valid regular expressions. Enabling or disabling
509 a feature will never modify the match semantics of a regular expression.
511 All features below are enabled by default.
513 ### Ecosystem features
516 When enabled, this will cause `regex` to use the standard library. Currently,
517 disabling this feature will always result in a compilation error. It is
518 intended to add `alloc`-only support to regex in the future.
520 ### Performance features
523 Enables all performance related features. This feature is enabled by default
524 and will always cover all features that improve performance, even if more
525 are added in the future.
527 Enables the use of a lazy DFA for matching. The lazy DFA is used to compile
528 portions of a regex to a very fast DFA on an as-needed basis. This can
529 result in substantial speedups, usually by an order of magnitude on large
530 haystacks. The lazy DFA does not bring in any new dependencies, but it can
531 make compile times longer.
533 Enables the use of aggressive inlining inside match routines. This reduces
534 the overhead of each match. The aggressive inlining, however, increases
535 compile times and binary size.
537 Enables the use of literal optimizations for speeding up matches. In some
538 cases, literal optimizations can result in speedups of _several_ orders of
539 magnitude. Disabling this drops the `aho-corasick` and `memchr` dependencies.
541 This feature used to enable a faster internal cache at the cost of using
542 additional dependencies, but this is no longer an option. A fast internal
543 cache is now used unconditionally with no additional dependencies. This may
544 change in the future.
549 Enables all Unicode features. This feature is enabled by default, and will
550 always cover all Unicode features, even if more are added in the future.
552 Provide the data for the
553 [Unicode `Age` property](https://www.unicode.org/reports/tr44/tr44-24.html#Character_Age).
554 This makes it possible to use classes like `\p{Age:6.0}` to refer to all
555 codepoints first introduced in Unicode 6.0
557 Provide the data for numerous Unicode boolean properties. The full list
558 is not included here, but contains properties like `Alphabetic`, `Emoji`,
559 `Lowercase`, `Math`, `Uppercase` and `White_Space`.
561 Provide the data for case insensitive matching using
562 [Unicode's "simple loose matches" specification](https://www.unicode.org/reports/tr18/#Simple_Loose_Matches).
563 * **unicode-gencat** -
565 [Unicode general categories](https://www.unicode.org/reports/tr44/tr44-24.html#General_Category_Values).
566 This includes, but is not limited to, `Decimal_Number`, `Letter`,
567 `Math_Symbol`, `Number` and `Punctuation`.
569 Provide the data for supporting the Unicode-aware Perl character classes,
570 corresponding to `\w`, `\s` and `\d`. This is also necessary for using
571 Unicode-aware word boundary assertions. Note that if this feature is
572 disabled, the `\s` and `\d` character classes are still available if the
573 `unicode-bool` and `unicode-gencat` features are enabled, respectively.
574 * **unicode-script** -
576 [Unicode scripts and script extensions](https://www.unicode.org/reports/tr24/).
577 This includes, but is not limited to, `Arabic`, `Cyrillic`, `Hebrew`,
579 * **unicode-segment** -
580 Provide the data necessary to provide the properties used to implement the
581 [Unicode text segmentation algorithms](https://www.unicode.org/reports/tr29/).
582 This enables using classes like `\p{gcb=Extend}`, `\p{wb=Katakana}` and
588 This crate can handle both untrusted regular expressions and untrusted
591 Untrusted regular expressions are handled by capping the size of a compiled
593 (See [`RegexBuilder::size_limit`](struct.RegexBuilder.html#method.size_limit).)
594 Without this, it would be trivial for an attacker to exhaust your system's
595 memory with expressions like `a{100}{100}{100}`.
597 Untrusted search text is allowed because the matching engine(s) in this
598 crate have time complexity `O(mn)` (with `m ~ regex` and `n ~ search
599 text`), which means there's no way to cause exponential blow-up like with
600 some other regular expression engines. (We pay for this by disallowing
601 features like arbitrary look-ahead and backreferences.)
603 When a DFA is used, pathological cases with exponential state blow-up are
604 avoided by constructing the DFA lazily or in an "online" manner. Therefore,
605 at most one new state can be created for each byte of input. This satisfies
606 our time complexity guarantees, but can lead to memory growth
607 proportional to the size of the input. As a stopgap, the DFA is only
608 allowed to store a fixed number of states. When the limit is reached, its
609 states are wiped and continues on, possibly duplicating previous work. If
610 the limit is reached too frequently, it gives up and hands control off to
611 another matching engine with fixed memory requirements.
612 (The DFA size limit can also be tweaked. See
613 [`RegexBuilder::dfa_size_limit`](struct.RegexBuilder.html#method.dfa_size_limit).)
616 #![deny(missing_docs)]
617 #![cfg_attr(test, deny(warnings))]
618 #![cfg_attr(feature = "pattern", feature(pattern))]
619 #![warn(missing_debug_implementations)]
621 #[cfg(not(feature = "std"))]
622 compile_error
!("`std` feature is currently required to build this crate");
624 #[cfg(feature = "perf-literal")]
625 extern crate aho_corasick
;
627 // extern crate doc_comment;
628 #[cfg(feature = "perf-literal")]
631 #[cfg_attr(feature = "perf-literal", macro_use)]
632 extern crate quickcheck
;
633 extern crate regex_syntax
as syntax
;
636 // doc_comment::doctest!("../README.md");
638 #[cfg(feature = "std")]
639 pub use error
::Error
;
640 #[cfg(feature = "std")]
641 pub use re_builder
::set_unicode
::*;
642 #[cfg(feature = "std")]
643 pub use re_builder
::unicode
::*;
644 #[cfg(feature = "std")]
645 pub use re_set
::unicode
::*;
646 #[cfg(feature = "std")]
647 #[cfg(feature = "std")]
648 pub use re_unicode
::{
649 escape
, CaptureLocations
, CaptureMatches
, CaptureNames
, Captures
,
650 Locations
, Match
, Matches
, NoExpand
, Regex
, Replacer
, ReplacerRef
, Split
,
651 SplitN
, SubCaptureMatches
,
655 Match regular expressions on arbitrary bytes.
657 This module provides a nearly identical API to the one found in the
658 top-level of this crate. There are two important differences:
660 1. Matching is done on `&[u8]` instead of `&str`. Additionally, `Vec<u8>`
661 is used where `String` would have been used.
662 2. Unicode support can be disabled even when disabling it would result in
663 matching invalid UTF-8 bytes.
665 # Example: match null terminated string
667 This shows how to find all null-terminated strings in a slice of bytes:
670 # use regex::bytes::Regex;
671 let re = Regex::new(r"(?-u)(?P<cstr>[^\x00]+)\x00").unwrap();
672 let text = b"foo\x00bar\x00baz\x00";
674 // Extract all of the strings without the null terminator from each match.
675 // The unwrap is OK here since a match requires the `cstr` capture to match.
676 let cstrs: Vec<&[u8]> =
677 re.captures_iter(text)
678 .map(|c| c.name("cstr").unwrap().as_bytes())
680 assert_eq!(vec![&b"foo"[..], &b"bar"[..], &b"baz"[..]], cstrs);
683 # Example: selectively enable Unicode support
685 This shows how to match an arbitrary byte pattern followed by a UTF-8 encoded
686 string (e.g., to extract a title from a Matroska file):
690 # use regex::bytes::Regex;
692 r"(?-u)\x7b\xa9(?:[\x80-\xfe]|[\x40-\xff].)(?u:(.*))"
694 let text = b"\x12\xd0\x3b\x5f\x7b\xa9\x85\xe2\x98\x83\x80\x98\x54\x76\x68\x65";
695 let caps = re.captures(text).unwrap();
697 // Notice that despite the `.*` at the end, it will only match valid UTF-8
698 // because Unicode mode was enabled with the `u` flag. Without the `u` flag,
699 // the `.*` would match the rest of the bytes.
700 let mat = caps.get(1).unwrap();
701 assert_eq!((7, 10), (mat.start(), mat.end()));
703 // If there was a match, Unicode mode guarantees that `title` is valid UTF-8.
704 let title = str::from_utf8(&caps[1]).unwrap();
705 assert_eq!("☃", title);
708 In general, if the Unicode flag is enabled in a capture group and that capture
709 is part of the overall match, then the capture is *guaranteed* to be valid
714 The supported syntax is pretty much the same as the syntax for Unicode
715 regular expressions with a few changes that make sense for matching arbitrary
718 1. The `u` flag can be disabled even when disabling it might cause the regex to
719 match invalid UTF-8. When the `u` flag is disabled, the regex is said to be in
720 "ASCII compatible" mode.
721 2. In ASCII compatible mode, neither Unicode scalar values nor Unicode
722 character classes are allowed.
723 3. In ASCII compatible mode, Perl character classes (`\w`, `\d` and `\s`)
724 revert to their typical ASCII definition. `\w` maps to `[[:word:]]`, `\d` maps
725 to `[[:digit:]]` and `\s` maps to `[[:space:]]`.
726 4. In ASCII compatible mode, word boundaries use the ASCII compatible `\w` to
727 determine whether a byte is a word byte or not.
728 5. Hexadecimal notation can be used to specify arbitrary bytes instead of
729 Unicode codepoints. For example, in ASCII compatible mode, `\xFF` matches the
730 literal byte `\xFF`, while in Unicode mode, `\xFF` is a Unicode codepoint that
731 matches its UTF-8 encoding of `\xC3\xBF`. Similarly for octal notation when
733 6. In ASCII compatible mode, `.` matches any *byte* except for `\n`. When the
734 `s` flag is additionally enabled, `.` matches any byte.
738 In general, one should expect performance on `&[u8]` to be roughly similar to
739 performance on `&str`.
741 #[cfg(feature = "std")]
743 pub use re_builder
::bytes
::*;
744 pub use re_builder
::set_bytes
::*;
746 pub use re_set
::bytes
::*;
751 #[cfg(feature = "perf-dfa")]
757 #[cfg(feature = "perf-literal")]
761 #[cfg(feature = "pattern")]
774 /// The `internal` module exists to support suspicious activity, such as
775 /// testing different matching engines and supporting the `regex-debug` CLI
778 #[cfg(feature = "std")]
780 pub use compile
::Compiler
;
781 pub use exec
::{Exec, ExecBuilder}
;
782 pub use input
::{Char, CharInput, Input, InputAt}
;
783 pub use literal
::LiteralSearcher
;
784 pub use prog
::{EmptyLook, Inst, InstRanges, Program}
;