1 mat
!(ascii_literal
, r
"a", "a", Some((0, 1)));
3 // Some crazy expressions from regular-expressions.info.
5 r
"\b(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b",
6 "num: 255", Some((5, 8)));
8 r
"\b(?:[0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\b",
10 mat
!(match_float1
, r
"[-+]?[0-9]*\.?[0-9]+", "0.1", Some((0, 3)));
11 mat
!(match_float2
, r
"[-+]?[0-9]*\.?[0-9]+", "0.1.2", Some((0, 3)));
12 mat
!(match_float3
, r
"[-+]?[0-9]*\.?[0-9]+", "a1.2", Some((1, 4)));
13 mat
!(match_float4
, r
"^[-+]?[0-9]*\.?[0-9]+$", "1.a", None
);
14 mat
!(match_email
, r
"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b",
15 "mine is jam.slam@gmail.com ", Some((8, 26)));
16 mat
!(match_email_not
, r
"(?i)\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b",
17 "mine is jam.slam@gmail ", None
);
18 mat
!(match_email_big
, r
"[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?",
19 "mine is jam.slam@gmail.com ", Some((8, 26)));
21 r
"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$",
22 "1900-01-01", Some((0, 10)));
24 r
"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$",
27 r
"^(19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01])$",
30 // Do some crazy dancing with the start/end assertions.
31 matiter
!(match_start_end_empty
, r
"^$", "", (0, 0));
32 matiter
!(match_start_end_empty_many_1
, r
"^$^$^$", "", (0, 0));
33 matiter
!(match_start_end_empty_many_2
, r
"^^^$$$", "", (0, 0));
34 matiter
!(match_start_end_empty_rev
, r
"$^", "", (0, 0));
35 matiter
!(match_start_end_empty_rep
, r
"(?:^$)*", "a\nb\nc",
36 (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5));
37 matiter
!(match_start_end_empty_rep_rev
, r
"(?:$^)*", "a\nb\nc",
38 (0, 0), (1, 1), (2, 2), (3, 3), (4, 4), (5, 5));
40 // Test negated character classes.
41 mat
!(negclass_letters
, r
"[^ac]", "acx", Some((2, 3)));
42 mat
!(negclass_letter_comma
, r
"[^a,]", "a,x", Some((2, 3)));
43 mat
!(negclass_letter_space
, r
"[^a\s]", "a x", Some((2, 3)));
44 mat
!(negclass_comma
, r
"[^,]", ",,x", Some((2, 3)));
45 mat
!(negclass_space
, r
"[^\s]", " a", Some((1, 2)));
46 mat
!(negclass_space_comma
, r
"[^,\s]", ", a", Some((2, 3)));
47 mat
!(negclass_comma_space
, r
"[^\s,]", " ,a", Some((2, 3)));
48 mat
!(negclass_ascii
, r
"[^[:alpha:]Z]", "A1", Some((1, 2)));
50 // Test that repeated empty expressions don't loop forever.
51 mat
!(lazy_many_many
, r
"((?:.*)*?)=", "a=b", Some((0, 2)));
52 mat
!(lazy_many_optional
, r
"((?:.?)*?)=", "a=b", Some((0, 2)));
53 mat
!(lazy_one_many_many
, r
"((?:.*)+?)=", "a=b", Some((0, 2)));
54 mat
!(lazy_one_many_optional
, r
"((?:.?)+?)=", "a=b", Some((0, 2)));
55 mat
!(lazy_range_min_many
, r
"((?:.*){1,}?)=", "a=b", Some((0, 2)));
56 mat
!(lazy_range_many
, r
"((?:.*){1,2}?)=", "a=b", Some((0, 2)));
57 mat
!(greedy_many_many
, r
"((?:.*)*)=", "a=b", Some((0, 2)));
58 mat
!(greedy_many_optional
, r
"((?:.?)*)=", "a=b", Some((0, 2)));
59 mat
!(greedy_one_many_many
, r
"((?:.*)+)=", "a=b", Some((0, 2)));
60 mat
!(greedy_one_many_optional
, r
"((?:.?)+)=", "a=b", Some((0, 2)));
61 mat
!(greedy_range_min_many
, r
"((?:.*){1,})=", "a=b", Some((0, 2)));
62 mat
!(greedy_range_many
, r
"((?:.*){1,2})=", "a=b", Some((0, 2)));
64 // Test that we handle various flavors of empty expressions.
65 matiter
!(match_empty1
, r
"", "", (0, 0));
66 matiter
!(match_empty2
, r
"", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
67 matiter
!(match_empty3
, r
"()", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
68 matiter
!(match_empty4
, r
"()*", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
69 matiter
!(match_empty5
, r
"()+", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
70 matiter
!(match_empty6
, r
"()?", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
71 matiter
!(match_empty7
, r
"()()", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
72 matiter
!(match_empty8
, r
"()+|z", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
73 matiter
!(match_empty9
, r
"z|()+", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
74 matiter
!(match_empty10
, r
"()+|b", "abc", (0, 0), (1, 1), (2, 2), (3, 3));
75 matiter
!(match_empty11
, r
"b|()+", "abc", (0, 0), (1, 2), (3, 3));
77 // Test that the DFA can handle pathological cases.
78 // (This should result in the DFA's cache being flushed too frequently, which
79 // should cause it to quit and fall back to the NFA algorithm.)
81 fn dfa_handles_pathological_case() {
82 fn ones_and_zeroes(count
: usize) -> String
{
83 use rand
::{Rng, thread_rng}
;
85 let mut rng
= thread_rng();
86 let mut s
= String
::new();
97 let re
= regex
!(r
"[01]*1[01]{20}$");
99 let mut pieces
= ones_and_zeroes(100_000);
101 pieces
.push_str(&ones_and_zeroes(20));
104 assert
!(re
.is_match(text
!(&*text
)));
108 fn nest_limit_makes_it_parse() {
109 use regex
::RegexBuilder
;