1 //===----------------------------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 
10 // <regex>
11 
12 // template <class BidirectionalIterator, class Allocator, class charT, class traits>
13 //     bool
14 //     regex_match(BidirectionalIterator first, BidirectionalIterator last,
15 //                  match_results<BidirectionalIterator, Allocator>& m,
16 //                  const basic_regex<charT, traits>& e,
17 //                  regex_constants::match_flag_type flags = regex_constants::match_default);
18 
19 #include <regex>
20 #include <cassert>
21 #include "test_macros.h"
22 #include "test_iterators.h"
23 
main(int,char **)24 int main(int, char**)
25 {
26     {
27         std::cmatch m;
28         const char s[] = "a";
29         assert(std::regex_match(s, m, std::regex("a")));
30         assert(m.size() == 1);
31         assert(!m.empty());
32         assert(!m.prefix().matched);
33         assert(m.prefix().first == s);
34         assert(m.prefix().second == m[0].first);
35         assert(!m.suffix().matched);
36         assert(m.suffix().first == m[0].second);
37         assert(m.suffix().second == s+1);
38         assert(m.length(0) == 1);
39         assert(m.position(0) == 0);
40         assert(m.str(0) == "a");
41     }
42     {
43         std::cmatch m;
44         const char s[] = "ab";
45         assert(std::regex_match(s, m, std::regex("ab")));
46         assert(m.size() == 1);
47         assert(!m.prefix().matched);
48         assert(m.prefix().first == s);
49         assert(m.prefix().second == m[0].first);
50         assert(!m.suffix().matched);
51         assert(m.suffix().first == m[0].second);
52         assert(m.suffix().second == s+2);
53         assert(m.length(0) == 2);
54         assert(m.position(0) == 0);
55         assert(m.str(0) == "ab");
56     }
57     {
58         std::cmatch m;
59         const char s[] = "ab";
60         assert(!std::regex_match(s, m, std::regex("ba")));
61         assert(m.size() == 0);
62         assert(m.empty());
63     }
64     {
65         std::cmatch m;
66         const char s[] = "aab";
67         assert(!std::regex_match(s, m, std::regex("ab")));
68         assert(m.size() == 0);
69     }
70     {
71         std::cmatch m;
72         const char s[] = "aab";
73         assert(!std::regex_match(s, m, std::regex("ab"),
74                                             std::regex_constants::match_continuous));
75         assert(m.size() == 0);
76     }
77     {
78         std::cmatch m;
79         const char s[] = "abcd";
80         assert(!std::regex_match(s, m, std::regex("bc")));
81         assert(m.size() == 0);
82     }
83     {
84         std::cmatch m;
85         const char s[] = "abbc";
86         assert(std::regex_match(s, m, std::regex("ab*c")));
87         assert(m.size() == 1);
88         assert(!m.prefix().matched);
89         assert(m.prefix().first == s);
90         assert(m.prefix().second == m[0].first);
91         assert(!m.suffix().matched);
92         assert(m.suffix().first == m[0].second);
93         assert(m.suffix().second == s+4);
94         assert(m.length(0) == 4);
95         assert(m.position(0) == 0);
96         assert(m.str(0) == s);
97     }
98     {
99         std::cmatch m;
100         const char s[] = "ababc";
101         assert(std::regex_match(s, m, std::regex("(ab)*c")));
102         assert(m.size() == 2);
103         assert(!m.prefix().matched);
104         assert(m.prefix().first == s);
105         assert(m.prefix().second == m[0].first);
106         assert(!m.suffix().matched);
107         assert(m.suffix().first == m[0].second);
108         assert(m.suffix().second == s+5);
109         assert(m.length(0) == 5);
110         assert(m.position(0) == 0);
111         assert(m.str(0) == s);
112         assert(m.length(1) == 2);
113         assert(m.position(1) == 2);
114         assert(m.str(1) == "ab");
115     }
116     {
117         std::cmatch m;
118         const char s[] = "abcdefghijk";
119         assert(!std::regex_match(s, m, std::regex("cd((e)fg)hi")));
120         assert(m.size() == 0);
121     }
122     {
123         std::cmatch m;
124         const char s[] = "abc";
125         assert(std::regex_match(s, m, std::regex("^abc")));
126         assert(m.size() == 1);
127         assert(!m.prefix().matched);
128         assert(m.prefix().first == s);
129         assert(m.prefix().second == m[0].first);
130         assert(!m.suffix().matched);
131         assert(m.suffix().first == m[0].second);
132         assert(m.suffix().second == s+3);
133         assert(m.length(0) == 3);
134         assert(m.position(0) == 0);
135         assert(m.str(0) == s);
136     }
137     {
138         std::cmatch m;
139         const char s[] = "abcd";
140         assert(!std::regex_match(s, m, std::regex("^abc")));
141         assert(m.size() == 0);
142     }
143     {
144         std::cmatch m;
145         const char s[] = "aabc";
146         assert(!std::regex_match(s, m, std::regex("^abc")));
147         assert(m.size() == 0);
148     }
149     {
150         std::cmatch m;
151         const char s[] = "abc";
152         assert(std::regex_match(s, m, std::regex("abc$")));
153         assert(m.size() == 1);
154         assert(!m.prefix().matched);
155         assert(m.prefix().first == s);
156         assert(m.prefix().second == m[0].first);
157         assert(!m.suffix().matched);
158         assert(m.suffix().first == m[0].second);
159         assert(m.suffix().second == s+3);
160         assert(m.length(0) == 3);
161         assert(m.position(0) == 0);
162         assert(m.str(0) == s);
163     }
164     {
165         std::cmatch m;
166         const char s[] = "efabc";
167         assert(!std::regex_match(s, m, std::regex("abc$")));
168         assert(m.size() == 0);
169     }
170     {
171         std::cmatch m;
172         const char s[] = "efabcg";
173         assert(!std::regex_match(s, m, std::regex("abc$")));
174         assert(m.size() == 0);
175     }
176     {
177         std::cmatch m;
178         const char s[] = "abc";
179         assert(std::regex_match(s, m, std::regex("a.c")));
180         assert(m.size() == 1);
181         assert(!m.prefix().matched);
182         assert(m.prefix().first == s);
183         assert(m.prefix().second == m[0].first);
184         assert(!m.suffix().matched);
185         assert(m.suffix().first == m[0].second);
186         assert(m.suffix().second == s+3);
187         assert(m.length(0) == 3);
188         assert(m.position(0) == 0);
189         assert(m.str(0) == s);
190     }
191     {
192         std::cmatch m;
193         const char s[] = "acc";
194         assert(std::regex_match(s, m, std::regex("a.c")));
195         assert(m.size() == 1);
196         assert(!m.prefix().matched);
197         assert(m.prefix().first == s);
198         assert(m.prefix().second == m[0].first);
199         assert(!m.suffix().matched);
200         assert(m.suffix().first == m[0].second);
201         assert(m.suffix().second == s+3);
202         assert(m.length(0) == 3);
203         assert(m.position(0) == 0);
204         assert(m.str(0) == s);
205     }
206     {
207         std::cmatch m;
208         const char s[] = "acc";
209         assert(std::regex_match(s, m, std::regex("a.c")));
210         assert(m.size() == 1);
211         assert(!m.prefix().matched);
212         assert(m.prefix().first == s);
213         assert(m.prefix().second == m[0].first);
214         assert(!m.suffix().matched);
215         assert(m.suffix().first == m[0].second);
216         assert(m.suffix().second == s+3);
217         assert(m.length(0) == 3);
218         assert(m.position(0) == 0);
219         assert(m.str(0) == s);
220     }
221     {
222         std::cmatch m;
223         const char s[] = "abcdef";
224         assert(std::regex_match(s, m, std::regex("(.*).*")));
225         assert(m.size() == 2);
226         assert(!m.prefix().matched);
227         assert(m.prefix().first == s);
228         assert(m.prefix().second == m[0].first);
229         assert(!m.suffix().matched);
230         assert(m.suffix().first == m[0].second);
231         assert(m.suffix().second == s+6);
232         assert(m.length(0) == 6);
233         assert(m.position(0) == 0);
234         assert(m.str(0) == s);
235         assert(m.length(1) == 6);
236         assert(m.position(1) == 0);
237         assert(m.str(1) == s);
238     }
239     {
240         std::cmatch m;
241         const char s[] = "bc";
242         assert(!std::regex_match(s, m, std::regex("(a*)*")));
243         assert(m.size() == 0);
244     }
245     {
246         std::cmatch m;
247         const char s[] = "abbc";
248         assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
249         assert(m.size() == 0);
250     }
251     {
252         std::cmatch m;
253         const char s[] = "abbbc";
254         assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
255         assert(m.size() == 1);
256         assert(!m.prefix().matched);
257         assert(m.prefix().first == s);
258         assert(m.prefix().second == m[0].first);
259         assert(!m.suffix().matched);
260         assert(m.suffix().first == m[0].second);
261         assert(m.suffix().second == m[0].second);
262         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
263         assert(m.position(0) == 0);
264         assert(m.str(0) == s);
265     }
266     {
267         std::cmatch m;
268         const char s[] = "abbbbc";
269         assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
270         assert(m.size() == 1);
271         assert(!m.prefix().matched);
272         assert(m.prefix().first == s);
273         assert(m.prefix().second == m[0].first);
274         assert(!m.suffix().matched);
275         assert(m.suffix().first == m[0].second);
276         assert(m.suffix().second == m[0].second);
277         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
278         assert(m.position(0) == 0);
279         assert(m.str(0) == s);
280     }
281     {
282         std::cmatch m;
283         const char s[] = "abbbbbc";
284         assert(std::regex_match(s, m, std::regex("ab{3,5}c")));
285         assert(m.size() == 1);
286         assert(!m.prefix().matched);
287         assert(m.prefix().first == s);
288         assert(m.prefix().second == m[0].first);
289         assert(!m.suffix().matched);
290         assert(m.suffix().first == m[0].second);
291         assert(m.suffix().second == m[0].second);
292         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
293         assert(m.position(0) == 0);
294         assert(m.str(0) == s);
295     }
296     {
297         std::cmatch m;
298         const char s[] = "adefc";
299         assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
300         assert(m.size() == 0);
301     }
302     {
303         std::cmatch m;
304         const char s[] = "abbbbbbc";
305         assert(!std::regex_match(s, m, std::regex("ab{3,5}c")));
306         assert(m.size() == 0);
307     }
308     {
309         std::cmatch m;
310         const char s[] = "adec";
311         assert(!std::regex_match(s, m, std::regex("a.{3,5}c")));
312         assert(m.size() == 0);
313     }
314     {
315         std::cmatch m;
316         const char s[] = "adefc";
317         assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
318         assert(m.size() == 1);
319         assert(!m.prefix().matched);
320         assert(m.prefix().first == s);
321         assert(m.prefix().second == m[0].first);
322         assert(!m.suffix().matched);
323         assert(m.suffix().first == m[0].second);
324         assert(m.suffix().second == m[0].second);
325         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
326         assert(m.position(0) == 0);
327         assert(m.str(0) == s);
328     }
329     {
330         std::cmatch m;
331         const char s[] = "adefgc";
332         assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
333         assert(m.size() == 1);
334         assert(!m.prefix().matched);
335         assert(m.prefix().first == s);
336         assert(m.prefix().second == m[0].first);
337         assert(!m.suffix().matched);
338         assert(m.suffix().first == m[0].second);
339         assert(m.suffix().second == m[0].second);
340         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
341         assert(m.position(0) == 0);
342         assert(m.str(0) == s);
343     }
344     {
345         std::cmatch m;
346         const char s[] = "adefghc";
347         assert(std::regex_match(s, m, std::regex("a.{3,5}c")));
348         assert(m.size() == 1);
349         assert(!m.prefix().matched);
350         assert(m.prefix().first == s);
351         assert(m.prefix().second == m[0].first);
352         assert(!m.suffix().matched);
353         assert(m.suffix().first == m[0].second);
354         assert(m.suffix().second == m[0].second);
355         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
356         assert(m.position(0) == 0);
357         assert(m.str(0) == s);
358     }
359     {
360         std::cmatch m;
361         const char s[] = "adefghic";
362         assert(!std::regex_match(s, m, std::regex("a.{3,5}c")));
363         assert(m.size() == 0);
364     }
365     {
366         std::cmatch m;
367         // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
368         const char s[] = "tournament";
369         assert(std::regex_match(s, m, std::regex("tour|to|tournament")));
370         assert(m.size() == 1);
371         assert(!m.prefix().matched);
372         assert(m.prefix().first == s);
373         assert(m.prefix().second == m[0].first);
374         assert(!m.suffix().matched);
375         assert(m.suffix().first == m[0].second);
376         assert(m.suffix().second == m[0].second);
377         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
378         assert(m.position(0) == 0);
379         assert(m.str(0) == s);
380     }
381     {
382         std::cmatch m;
383         // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
384         const char s[] = "tournamenttotour";
385         assert(
386             std::regex_match(s, m, std::regex("(tour|to|tournament)+",
387                                               std::regex_constants::nosubs)));
388         assert(m.size() == 1);
389         assert(!m.prefix().matched);
390         assert(m.prefix().first == s);
391         assert(m.prefix().second == m[0].first);
392         assert(!m.suffix().matched);
393         assert(m.suffix().first == m[0].second);
394         assert(m.suffix().second == m[0].second);
395         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
396         assert(m.position(0) == 0);
397         assert(m.str(0) == s);
398     }
399     {
400         std::cmatch m;
401         const char s[] = "ttotour";
402         assert(std::regex_match(s, m, std::regex("(tour|to|t)+")));
403         assert(m.size() == 2);
404         assert(!m.prefix().matched);
405         assert(m.prefix().first == s);
406         assert(m.prefix().second == m[0].first);
407         assert(!m.suffix().matched);
408         assert(m.suffix().first == m[0].second);
409         assert(m.suffix().second == m[0].second);
410         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
411         assert(m.position(0) == 0);
412         assert(m.str(0) == s);
413         assert(m.length(1) == 4);
414         assert(m.position(1) == 3);
415         assert(m.str(1) == "tour");
416     }
417     {
418         std::cmatch m;
419         const char s[] = "-ab,ab-";
420         assert(!std::regex_match(s, m, std::regex("-(.*),\1-")));
421         assert(m.size() == 0);
422     }
423     {
424         std::cmatch m;
425         const char s[] = "-ab,ab-";
426         assert(std::regex_match(s, m, std::regex("-.*,.*-")));
427         assert(m.size() == 1);
428         assert(!m.prefix().matched);
429         assert(m.prefix().first == s);
430         assert(m.prefix().second == m[0].first);
431         assert(!m.suffix().matched);
432         assert(m.suffix().first == m[0].second);
433         assert(m.suffix().second == m[0].second);
434         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
435         assert(m.position(0) == 0);
436         assert(m.str(0) == s);
437     }
438     {
439         std::cmatch m;
440         const char s[] = "a";
441         assert(std::regex_match(s, m, std::regex("^[a]$")));
442         assert(m.size() == 1);
443         assert(!m.prefix().matched);
444         assert(m.prefix().first == s);
445         assert(m.prefix().second == m[0].first);
446         assert(!m.suffix().matched);
447         assert(m.suffix().first == m[0].second);
448         assert(m.suffix().second == m[0].second);
449         assert(m.length(0) == 1);
450         assert(m.position(0) == 0);
451         assert(m.str(0) == "a");
452     }
453     {
454         std::cmatch m;
455         const char s[] = "a";
456         assert(std::regex_match(s, m, std::regex("^[ab]$")));
457         assert(m.size() == 1);
458         assert(!m.prefix().matched);
459         assert(m.prefix().first == s);
460         assert(m.prefix().second == m[0].first);
461         assert(!m.suffix().matched);
462         assert(m.suffix().first == m[0].second);
463         assert(m.suffix().second == m[0].second);
464         assert(m.length(0) == 1);
465         assert(m.position(0) == 0);
466         assert(m.str(0) == "a");
467     }
468     {
469         std::cmatch m;
470         const char s[] = "c";
471         assert(std::regex_match(s, m, std::regex("^[a-f]$")));
472         assert(m.size() == 1);
473         assert(!m.prefix().matched);
474         assert(m.prefix().first == s);
475         assert(m.prefix().second == m[0].first);
476         assert(!m.suffix().matched);
477         assert(m.suffix().first == m[0].second);
478         assert(m.suffix().second == m[0].second);
479         assert(m.length(0) == 1);
480         assert(m.position(0) == 0);
481         assert(m.str(0) == s);
482     }
483     {
484         std::cmatch m;
485         const char s[] = "g";
486         assert(!std::regex_match(s, m, std::regex("^[a-f]$")));
487         assert(m.size() == 0);
488     }
489     {
490         std::cmatch m;
491         const char s[] = "Iraqi";
492         assert(!std::regex_match(s, m, std::regex("q[^u]")));
493         assert(m.size() == 0);
494     }
495     {
496         std::cmatch m;
497         const char s[] = "Iraq";
498         assert(!std::regex_match(s, m, std::regex("q[^u]")));
499         assert(m.size() == 0);
500     }
501     {
502         std::cmatch m;
503         const char s[] = "AmB";
504         assert(std::regex_match(s, m, std::regex("A[[:lower:]]B")));
505         assert(m.size() == 1);
506         assert(!m.prefix().matched);
507         assert(m.prefix().first == s);
508         assert(m.prefix().second == m[0].first);
509         assert(!m.suffix().matched);
510         assert(m.suffix().first == m[0].second);
511         assert(m.suffix().second == m[0].second);
512         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
513         assert(m.position(0) == 0);
514         assert(m.str(0) == s);
515     }
516     {
517         std::cmatch m;
518         const char s[] = "AMB";
519         assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B")));
520         assert(m.size() == 0);
521     }
522     {
523         std::cmatch m;
524         const char s[] = "AMB";
525         assert(std::regex_match(s, m, std::regex("A[^[:lower:]]B")));
526         assert(m.size() == 1);
527         assert(!m.prefix().matched);
528         assert(m.prefix().first == s);
529         assert(m.prefix().second == m[0].first);
530         assert(!m.suffix().matched);
531         assert(m.suffix().first == m[0].second);
532         assert(m.suffix().second == m[0].second);
533         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
534         assert(m.position(0) == 0);
535         assert(m.str(0) == s);
536     }
537     {
538         std::cmatch m;
539         const char s[] = "AmB";
540         assert(!std::regex_match(s, m, std::regex("A[^[:lower:]]B")));
541         assert(m.size() == 0);
542     }
543     {
544         std::cmatch m;
545         const char s[] = "A5B";
546         assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B")));
547         assert(m.size() == 0);
548     }
549     {
550         std::cmatch m;
551         const char s[] = "A?B";
552         assert(std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B")));
553         assert(m.size() == 1);
554         assert(!m.prefix().matched);
555         assert(m.prefix().first == s);
556         assert(m.prefix().second == m[0].first);
557         assert(!m.suffix().matched);
558         assert(m.suffix().first == m[0].second);
559         assert(m.suffix().second == m[0].second);
560         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
561         assert(m.position(0) == 0);
562         assert(m.str(0) == s);
563     }
564     {
565         std::cmatch m;
566         const char s[] = "-";
567         assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
568         assert(m.size() == 1);
569         assert(!m.prefix().matched);
570         assert(m.prefix().first == s);
571         assert(m.prefix().second == m[0].first);
572         assert(!m.suffix().matched);
573         assert(m.suffix().first == m[0].second);
574         assert(m.suffix().second == m[0].second);
575         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
576         assert(m.position(0) == 0);
577         assert(m.str(0) == s);
578     }
579     {
580         std::cmatch m;
581         const char s[] = "z";
582         assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
583         assert(m.size() == 1);
584         assert(!m.prefix().matched);
585         assert(m.prefix().first == s);
586         assert(m.prefix().second == m[0].first);
587         assert(!m.suffix().matched);
588         assert(m.suffix().first == m[0].second);
589         assert(m.suffix().second == m[0].second);
590         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
591         assert(m.position(0) == 0);
592         assert(m.str(0) == s);
593     }
594     {
595         std::cmatch m;
596         const char s[] = "m";
597         assert(!std::regex_match(s, m, std::regex("[a[.hyphen.]z]")));
598         assert(m.size() == 0);
599     }
600     {
601         std::cmatch m;
602         const char s[] = "foobar";
603         assert(std::regex_match(s, m, std::regex("[^\\0]*")));
604         assert(m.size() == 1);
605     }
606     {
607         std::cmatch m;
608         const char s[] = "foo\0bar";
609         assert(std::regex_match(s, s+7, m, std::regex("[abfor\\0]*")));
610         assert(m.size() == 1);
611     }
612     {
613         std::cmatch m;
614         const char s[] = "01a45cef9";
615         assert(!std::regex_match(s, m, std::regex("[ace1-9]*")));
616         assert(m.size() == 0);
617     }
618     {
619         std::cmatch m;
620         const char s[] = "01a45cef9";
621         assert(!std::regex_match(s, m, std::regex("[ace1-9]+")));
622         assert(m.size() == 0);
623     }
624     {
625         const char r[] = "^[-+]?[0-9]+[CF]$";
626         std::ptrdiff_t sr = std::char_traits<char>::length(r);
627         typedef forward_iterator<const char*> FI;
628         typedef bidirectional_iterator<const char*> BI;
629         std::regex regex(FI(r), FI(r+sr));
630         std::match_results<BI> m;
631         const char s[] = "-40C";
632         std::ptrdiff_t ss = std::char_traits<char>::length(s);
633         assert(std::regex_match(BI(s), BI(s+ss), m, regex));
634         assert(m.size() == 1);
635         assert(!m.prefix().matched);
636         assert(m.prefix().first == BI(s));
637         assert(m.prefix().second == m[0].first);
638         assert(!m.suffix().matched);
639         assert(m.suffix().first == m[0].second);
640         assert(m.suffix().second == m[0].second);
641         assert(m.length(0) == 4);
642         assert(m.position(0) == 0);
643         assert(m.str(0) == s);
644     }
645     {
646         std::cmatch m;
647         const char s[] = "Jeff Jeffs ";
648         assert(!std::regex_match(s, m, std::regex("Jeff(?=s\\b)")));
649         assert(m.size() == 0);
650     }
651     {
652         std::cmatch m;
653         const char s[] = "Jeffs Jeff";
654         assert(!std::regex_match(s, m, std::regex("Jeff(?!s\\b)")));
655         assert(m.size() == 0);
656     }
657     {
658         std::cmatch m;
659         const char s[] = "5%k";
660         assert(std::regex_match(s, m, std::regex("\\d[\\W]k")));
661         assert(m.size() == 1);
662         assert(!m.prefix().matched);
663         assert(m.prefix().first == s);
664         assert(m.prefix().second == m[0].first);
665         assert(!m.suffix().matched);
666         assert(m.suffix().first == m[0].second);
667         assert(m.suffix().second == s + std::char_traits<char>::length(s));
668         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<char>::length(s));
669         assert(m.position(0) == 0);
670         assert(m.str(0) == s);
671     }
672 
673     {
674         std::wcmatch m;
675         const wchar_t s[] = L"a";
676         assert(std::regex_match(s, m, std::wregex(L"a")));
677         assert(m.size() == 1);
678         assert(!m.empty());
679         assert(!m.prefix().matched);
680         assert(m.prefix().first == s);
681         assert(m.prefix().second == m[0].first);
682         assert(!m.suffix().matched);
683         assert(m.suffix().first == m[0].second);
684         assert(m.suffix().second == s+1);
685         assert(m.length(0) == 1);
686         assert(m.position(0) == 0);
687         assert(m.str(0) == L"a");
688     }
689     {
690         std::wcmatch m;
691         const wchar_t s[] = L"ab";
692         assert(std::regex_match(s, m, std::wregex(L"ab")));
693         assert(m.size() == 1);
694         assert(!m.prefix().matched);
695         assert(m.prefix().first == s);
696         assert(m.prefix().second == m[0].first);
697         assert(!m.suffix().matched);
698         assert(m.suffix().first == m[0].second);
699         assert(m.suffix().second == s+2);
700         assert(m.length(0) == 2);
701         assert(m.position(0) == 0);
702         assert(m.str(0) == L"ab");
703     }
704     {
705         std::wcmatch m;
706         const wchar_t s[] = L"ab";
707         assert(!std::regex_match(s, m, std::wregex(L"ba")));
708         assert(m.size() == 0);
709         assert(m.empty());
710     }
711     {
712         std::wcmatch m;
713         const wchar_t s[] = L"aab";
714         assert(!std::regex_match(s, m, std::wregex(L"ab")));
715         assert(m.size() == 0);
716     }
717     {
718         std::wcmatch m;
719         const wchar_t s[] = L"aab";
720         assert(!std::regex_match(s, m, std::wregex(L"ab"),
721                                             std::regex_constants::match_continuous));
722         assert(m.size() == 0);
723     }
724     {
725         std::wcmatch m;
726         const wchar_t s[] = L"abcd";
727         assert(!std::regex_match(s, m, std::wregex(L"bc")));
728         assert(m.size() == 0);
729     }
730     {
731         std::wcmatch m;
732         const wchar_t s[] = L"abbc";
733         assert(std::regex_match(s, m, std::wregex(L"ab*c")));
734         assert(m.size() == 1);
735         assert(!m.prefix().matched);
736         assert(m.prefix().first == s);
737         assert(m.prefix().second == m[0].first);
738         assert(!m.suffix().matched);
739         assert(m.suffix().first == m[0].second);
740         assert(m.suffix().second == s+4);
741         assert(m.length(0) == 4);
742         assert(m.position(0) == 0);
743         assert(m.str(0) == s);
744     }
745     {
746         std::wcmatch m;
747         const wchar_t s[] = L"ababc";
748         assert(std::regex_match(s, m, std::wregex(L"(ab)*c")));
749         assert(m.size() == 2);
750         assert(!m.prefix().matched);
751         assert(m.prefix().first == s);
752         assert(m.prefix().second == m[0].first);
753         assert(!m.suffix().matched);
754         assert(m.suffix().first == m[0].second);
755         assert(m.suffix().second == s+5);
756         assert(m.length(0) == 5);
757         assert(m.position(0) == 0);
758         assert(m.str(0) == s);
759         assert(m.length(1) == 2);
760         assert(m.position(1) == 2);
761         assert(m.str(1) == L"ab");
762     }
763     {
764         std::wcmatch m;
765         const wchar_t s[] = L"abcdefghijk";
766         assert(!std::regex_match(s, m, std::wregex(L"cd((e)fg)hi")));
767         assert(m.size() == 0);
768     }
769     {
770         std::wcmatch m;
771         const wchar_t s[] = L"abc";
772         assert(std::regex_match(s, m, std::wregex(L"^abc")));
773         assert(m.size() == 1);
774         assert(!m.prefix().matched);
775         assert(m.prefix().first == s);
776         assert(m.prefix().second == m[0].first);
777         assert(!m.suffix().matched);
778         assert(m.suffix().first == m[0].second);
779         assert(m.suffix().second == s+3);
780         assert(m.length(0) == 3);
781         assert(m.position(0) == 0);
782         assert(m.str(0) == s);
783     }
784     {
785         std::wcmatch m;
786         const wchar_t s[] = L"abcd";
787         assert(!std::regex_match(s, m, std::wregex(L"^abc")));
788         assert(m.size() == 0);
789     }
790     {
791         std::wcmatch m;
792         const wchar_t s[] = L"aabc";
793         assert(!std::regex_match(s, m, std::wregex(L"^abc")));
794         assert(m.size() == 0);
795     }
796     {
797         std::wcmatch m;
798         const wchar_t s[] = L"abc";
799         assert(std::regex_match(s, m, std::wregex(L"abc$")));
800         assert(m.size() == 1);
801         assert(!m.prefix().matched);
802         assert(m.prefix().first == s);
803         assert(m.prefix().second == m[0].first);
804         assert(!m.suffix().matched);
805         assert(m.suffix().first == m[0].second);
806         assert(m.suffix().second == s+3);
807         assert(m.length(0) == 3);
808         assert(m.position(0) == 0);
809         assert(m.str(0) == s);
810     }
811     {
812         std::wcmatch m;
813         const wchar_t s[] = L"efabc";
814         assert(!std::regex_match(s, m, std::wregex(L"abc$")));
815         assert(m.size() == 0);
816     }
817     {
818         std::wcmatch m;
819         const wchar_t s[] = L"efabcg";
820         assert(!std::regex_match(s, m, std::wregex(L"abc$")));
821         assert(m.size() == 0);
822     }
823     {
824         std::wcmatch m;
825         const wchar_t s[] = L"abc";
826         assert(std::regex_match(s, m, std::wregex(L"a.c")));
827         assert(m.size() == 1);
828         assert(!m.prefix().matched);
829         assert(m.prefix().first == s);
830         assert(m.prefix().second == m[0].first);
831         assert(!m.suffix().matched);
832         assert(m.suffix().first == m[0].second);
833         assert(m.suffix().second == s+3);
834         assert(m.length(0) == 3);
835         assert(m.position(0) == 0);
836         assert(m.str(0) == s);
837     }
838     {
839         std::wcmatch m;
840         const wchar_t s[] = L"acc";
841         assert(std::regex_match(s, m, std::wregex(L"a.c")));
842         assert(m.size() == 1);
843         assert(!m.prefix().matched);
844         assert(m.prefix().first == s);
845         assert(m.prefix().second == m[0].first);
846         assert(!m.suffix().matched);
847         assert(m.suffix().first == m[0].second);
848         assert(m.suffix().second == s+3);
849         assert(m.length(0) == 3);
850         assert(m.position(0) == 0);
851         assert(m.str(0) == s);
852     }
853     {
854         std::wcmatch m;
855         const wchar_t s[] = L"acc";
856         assert(std::regex_match(s, m, std::wregex(L"a.c")));
857         assert(m.size() == 1);
858         assert(!m.prefix().matched);
859         assert(m.prefix().first == s);
860         assert(m.prefix().second == m[0].first);
861         assert(!m.suffix().matched);
862         assert(m.suffix().first == m[0].second);
863         assert(m.suffix().second == s+3);
864         assert(m.length(0) == 3);
865         assert(m.position(0) == 0);
866         assert(m.str(0) == s);
867     }
868     {
869         std::wcmatch m;
870         const wchar_t s[] = L"abcdef";
871         assert(std::regex_match(s, m, std::wregex(L"(.*).*")));
872         assert(m.size() == 2);
873         assert(!m.prefix().matched);
874         assert(m.prefix().first == s);
875         assert(m.prefix().second == m[0].first);
876         assert(!m.suffix().matched);
877         assert(m.suffix().first == m[0].second);
878         assert(m.suffix().second == s+6);
879         assert(m.length(0) == 6);
880         assert(m.position(0) == 0);
881         assert(m.str(0) == s);
882         assert(m.length(1) == 6);
883         assert(m.position(1) == 0);
884         assert(m.str(1) == s);
885     }
886     {
887         std::wcmatch m;
888         const wchar_t s[] = L"bc";
889         assert(!std::regex_match(s, m, std::wregex(L"(a*)*")));
890         assert(m.size() == 0);
891     }
892     {
893         std::wcmatch m;
894         const wchar_t s[] = L"abbc";
895         assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
896         assert(m.size() == 0);
897     }
898     {
899         std::wcmatch m;
900         const wchar_t s[] = L"abbbc";
901         assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
902         assert(m.size() == 1);
903         assert(!m.prefix().matched);
904         assert(m.prefix().first == s);
905         assert(m.prefix().second == m[0].first);
906         assert(!m.suffix().matched);
907         assert(m.suffix().first == m[0].second);
908         assert(m.suffix().second == m[0].second);
909         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
910         assert(m.position(0) == 0);
911         assert(m.str(0) == s);
912     }
913     {
914         std::wcmatch m;
915         const wchar_t s[] = L"abbbbc";
916         assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
917         assert(m.size() == 1);
918         assert(!m.prefix().matched);
919         assert(m.prefix().first == s);
920         assert(m.prefix().second == m[0].first);
921         assert(!m.suffix().matched);
922         assert(m.suffix().first == m[0].second);
923         assert(m.suffix().second == m[0].second);
924         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
925         assert(m.position(0) == 0);
926         assert(m.str(0) == s);
927     }
928     {
929         std::wcmatch m;
930         const wchar_t s[] = L"abbbbbc";
931         assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
932         assert(m.size() == 1);
933         assert(!m.prefix().matched);
934         assert(m.prefix().first == s);
935         assert(m.prefix().second == m[0].first);
936         assert(!m.suffix().matched);
937         assert(m.suffix().first == m[0].second);
938         assert(m.suffix().second == m[0].second);
939         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
940         assert(m.position(0) == 0);
941         assert(m.str(0) == s);
942     }
943     {
944         std::wcmatch m;
945         const wchar_t s[] = L"adefc";
946         assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
947         assert(m.size() == 0);
948     }
949     {
950         std::wcmatch m;
951         const wchar_t s[] = L"abbbbbbc";
952         assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c")));
953         assert(m.size() == 0);
954     }
955     {
956         std::wcmatch m;
957         const wchar_t s[] = L"adec";
958         assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
959         assert(m.size() == 0);
960     }
961     {
962         std::wcmatch m;
963         const wchar_t s[] = L"adefc";
964         assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
965         assert(m.size() == 1);
966         assert(!m.prefix().matched);
967         assert(m.prefix().first == s);
968         assert(m.prefix().second == m[0].first);
969         assert(!m.suffix().matched);
970         assert(m.suffix().first == m[0].second);
971         assert(m.suffix().second == m[0].second);
972         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
973         assert(m.position(0) == 0);
974         assert(m.str(0) == s);
975     }
976     {
977         std::wcmatch m;
978         const wchar_t s[] = L"adefgc";
979         assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
980         assert(m.size() == 1);
981         assert(!m.prefix().matched);
982         assert(m.prefix().first == s);
983         assert(m.prefix().second == m[0].first);
984         assert(!m.suffix().matched);
985         assert(m.suffix().first == m[0].second);
986         assert(m.suffix().second == m[0].second);
987         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
988         assert(m.position(0) == 0);
989         assert(m.str(0) == s);
990     }
991     {
992         std::wcmatch m;
993         const wchar_t s[] = L"adefghc";
994         assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
995         assert(m.size() == 1);
996         assert(!m.prefix().matched);
997         assert(m.prefix().first == s);
998         assert(m.prefix().second == m[0].first);
999         assert(!m.suffix().matched);
1000         assert(m.suffix().first == m[0].second);
1001         assert(m.suffix().second == m[0].second);
1002         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1003         assert(m.position(0) == 0);
1004         assert(m.str(0) == s);
1005     }
1006     {
1007         std::wcmatch m;
1008         const wchar_t s[] = L"adefghic";
1009         assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c")));
1010         assert(m.size() == 0);
1011     }
1012     {
1013         std::wcmatch m;
1014         // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
1015         const wchar_t s[] = L"tournament";
1016         assert(std::regex_match(s, m, std::wregex(L"tour|to|tournament")));
1017         assert(m.size() == 1);
1018         assert(!m.prefix().matched);
1019         assert(m.prefix().first == s);
1020         assert(m.prefix().second == m[0].first);
1021         assert(!m.suffix().matched);
1022         assert(m.suffix().first == m[0].second);
1023         assert(m.suffix().second == m[0].second);
1024         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1025         assert(m.position(0) == 0);
1026         assert(m.str(0) == s);
1027     }
1028     {
1029         std::wcmatch m;
1030         // http://www.open-std.org/jtc1/sc22/wg21/docs/lwg-defects.html#2273
1031         const wchar_t s[] = L"tournamenttotour";
1032         assert(
1033             std::regex_match(s, m, std::wregex(L"(tour|to|tournament)+",
1034                                                std::regex_constants::nosubs)));
1035         assert(m.size() == 1);
1036         assert(!m.prefix().matched);
1037         assert(m.prefix().first == s);
1038         assert(m.prefix().second == m[0].first);
1039         assert(!m.suffix().matched);
1040         assert(m.suffix().first == m[0].second);
1041         assert(m.suffix().second == m[0].second);
1042         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1043         assert(m.position(0) == 0);
1044         assert(m.str(0) == s);
1045     }
1046     {
1047         std::wcmatch m;
1048         const wchar_t s[] = L"ttotour";
1049         assert(std::regex_match(s, m, std::wregex(L"(tour|to|t)+")));
1050         assert(m.size() == 2);
1051         assert(!m.prefix().matched);
1052         assert(m.prefix().first == s);
1053         assert(m.prefix().second == m[0].first);
1054         assert(!m.suffix().matched);
1055         assert(m.suffix().first == m[0].second);
1056         assert(m.suffix().second == m[0].second);
1057         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1058         assert(m.position(0) == 0);
1059         assert(m.str(0) == s);
1060         assert(m.length(1) == 4);
1061         assert(m.position(1) == 3);
1062         assert(m.str(1) == L"tour");
1063     }
1064     {
1065         std::wcmatch m;
1066         const wchar_t s[] = L"-ab,ab-";
1067         assert(!std::regex_match(s, m, std::wregex(L"-(.*),\1-")));
1068         assert(m.size() == 0);
1069     }
1070     {
1071         std::wcmatch m;
1072         const wchar_t s[] = L"-ab,ab-";
1073         assert(std::regex_match(s, m, std::wregex(L"-.*,.*-")));
1074         assert(m.size() == 1);
1075         assert(!m.prefix().matched);
1076         assert(m.prefix().first == s);
1077         assert(m.prefix().second == m[0].first);
1078         assert(!m.suffix().matched);
1079         assert(m.suffix().first == m[0].second);
1080         assert(m.suffix().second == m[0].second);
1081         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1082         assert(m.position(0) == 0);
1083         assert(m.str(0) == s);
1084     }
1085     {
1086         std::wcmatch m;
1087         const wchar_t s[] = L"a";
1088         assert(std::regex_match(s, m, std::wregex(L"^[a]$")));
1089         assert(m.size() == 1);
1090         assert(!m.prefix().matched);
1091         assert(m.prefix().first == s);
1092         assert(m.prefix().second == m[0].first);
1093         assert(!m.suffix().matched);
1094         assert(m.suffix().first == m[0].second);
1095         assert(m.suffix().second == m[0].second);
1096         assert(m.length(0) == 1);
1097         assert(m.position(0) == 0);
1098         assert(m.str(0) == L"a");
1099     }
1100     {
1101         std::wcmatch m;
1102         const wchar_t s[] = L"a";
1103         assert(std::regex_match(s, m, std::wregex(L"^[ab]$")));
1104         assert(m.size() == 1);
1105         assert(!m.prefix().matched);
1106         assert(m.prefix().first == s);
1107         assert(m.prefix().second == m[0].first);
1108         assert(!m.suffix().matched);
1109         assert(m.suffix().first == m[0].second);
1110         assert(m.suffix().second == m[0].second);
1111         assert(m.length(0) == 1);
1112         assert(m.position(0) == 0);
1113         assert(m.str(0) == L"a");
1114     }
1115     {
1116         std::wcmatch m;
1117         const wchar_t s[] = L"c";
1118         assert(std::regex_match(s, m, std::wregex(L"^[a-f]$")));
1119         assert(m.size() == 1);
1120         assert(!m.prefix().matched);
1121         assert(m.prefix().first == s);
1122         assert(m.prefix().second == m[0].first);
1123         assert(!m.suffix().matched);
1124         assert(m.suffix().first == m[0].second);
1125         assert(m.suffix().second == m[0].second);
1126         assert(m.length(0) == 1);
1127         assert(m.position(0) == 0);
1128         assert(m.str(0) == s);
1129     }
1130     {
1131         std::wcmatch m;
1132         const wchar_t s[] = L"g";
1133         assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$")));
1134         assert(m.size() == 0);
1135     }
1136     {
1137         std::wcmatch m;
1138         const wchar_t s[] = L"Iraqi";
1139         assert(!std::regex_match(s, m, std::wregex(L"q[^u]")));
1140         assert(m.size() == 0);
1141     }
1142     {
1143         std::wcmatch m;
1144         const wchar_t s[] = L"Iraq";
1145         assert(!std::regex_match(s, m, std::wregex(L"q[^u]")));
1146         assert(m.size() == 0);
1147     }
1148     {
1149         std::wcmatch m;
1150         const wchar_t s[] = L"AmB";
1151         assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B")));
1152         assert(m.size() == 1);
1153         assert(!m.prefix().matched);
1154         assert(m.prefix().first == s);
1155         assert(m.prefix().second == m[0].first);
1156         assert(!m.suffix().matched);
1157         assert(m.suffix().first == m[0].second);
1158         assert(m.suffix().second == m[0].second);
1159         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1160         assert(m.position(0) == 0);
1161         assert(m.str(0) == s);
1162     }
1163     {
1164         std::wcmatch m;
1165         const wchar_t s[] = L"AMB";
1166         assert(!std::regex_match(s, m, std::wregex(L"A[[:lower:]]B")));
1167         assert(m.size() == 0);
1168     }
1169     {
1170         std::wcmatch m;
1171         const wchar_t s[] = L"AMB";
1172         assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B")));
1173         assert(m.size() == 1);
1174         assert(!m.prefix().matched);
1175         assert(m.prefix().first == s);
1176         assert(m.prefix().second == m[0].first);
1177         assert(!m.suffix().matched);
1178         assert(m.suffix().first == m[0].second);
1179         assert(m.suffix().second == m[0].second);
1180         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1181         assert(m.position(0) == 0);
1182         assert(m.str(0) == s);
1183     }
1184     {
1185         std::wcmatch m;
1186         const wchar_t s[] = L"AmB";
1187         assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B")));
1188         assert(m.size() == 0);
1189     }
1190     {
1191         std::wcmatch m;
1192         const wchar_t s[] = L"A5B";
1193         assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
1194         assert(m.size() == 0);
1195     }
1196     {
1197         std::wcmatch m;
1198         const wchar_t s[] = L"A?B";
1199         assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B")));
1200         assert(m.size() == 1);
1201         assert(!m.prefix().matched);
1202         assert(m.prefix().first == s);
1203         assert(m.prefix().second == m[0].first);
1204         assert(!m.suffix().matched);
1205         assert(m.suffix().first == m[0].second);
1206         assert(m.suffix().second == m[0].second);
1207         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1208         assert(m.position(0) == 0);
1209         assert(m.str(0) == s);
1210     }
1211     {
1212         std::wcmatch m;
1213         const wchar_t s[] = L"-";
1214         assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
1215         assert(m.size() == 1);
1216         assert(!m.prefix().matched);
1217         assert(m.prefix().first == s);
1218         assert(m.prefix().second == m[0].first);
1219         assert(!m.suffix().matched);
1220         assert(m.suffix().first == m[0].second);
1221         assert(m.suffix().second == m[0].second);
1222         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1223         assert(m.position(0) == 0);
1224         assert(m.str(0) == s);
1225     }
1226     {
1227         std::wcmatch m;
1228         const wchar_t s[] = L"z";
1229         assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
1230         assert(m.size() == 1);
1231         assert(!m.prefix().matched);
1232         assert(m.prefix().first == s);
1233         assert(m.prefix().second == m[0].first);
1234         assert(!m.suffix().matched);
1235         assert(m.suffix().first == m[0].second);
1236         assert(m.suffix().second == m[0].second);
1237         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1238         assert(m.position(0) == 0);
1239         assert(m.str(0) == s);
1240     }
1241     {
1242         std::wcmatch m;
1243         const wchar_t s[] = L"m";
1244         assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]")));
1245         assert(m.size() == 0);
1246     }
1247     {
1248         std::wcmatch m;
1249         const wchar_t s[] = L"01a45cef9";
1250         assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*")));
1251         assert(m.size() == 0);
1252     }
1253     {
1254         std::wcmatch m;
1255         const wchar_t s[] = L"01a45cef9";
1256         assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]+")));
1257         assert(m.size() == 0);
1258     }
1259     {
1260         const wchar_t r[] = L"^[-+]?[0-9]+[CF]$";
1261         std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r);
1262         typedef forward_iterator<const wchar_t*> FI;
1263         typedef bidirectional_iterator<const wchar_t*> BI;
1264         std::wregex regex(FI(r), FI(r+sr));
1265         std::match_results<BI> m;
1266         const wchar_t s[] = L"-40C";
1267         std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s);
1268         assert(std::regex_match(BI(s), BI(s+ss), m, regex));
1269         assert(m.size() == 1);
1270         assert(!m.prefix().matched);
1271         assert(m.prefix().first == BI(s));
1272         assert(m.prefix().second == m[0].first);
1273         assert(!m.suffix().matched);
1274         assert(m.suffix().first == m[0].second);
1275         assert(m.suffix().second == m[0].second);
1276         assert(m.length(0) == 4);
1277         assert(m.position(0) == 0);
1278         assert(m.str(0) == s);
1279     }
1280     {
1281         std::wcmatch m;
1282         const wchar_t s[] = L"Jeff Jeffs ";
1283         assert(!std::regex_match(s, m, std::wregex(L"Jeff(?=s\\b)")));
1284         assert(m.size() == 0);
1285     }
1286     {
1287         std::wcmatch m;
1288         const wchar_t s[] = L"Jeffs Jeff";
1289         assert(!std::regex_match(s, m, std::wregex(L"Jeff(?!s\\b)")));
1290         assert(m.size() == 0);
1291     }
1292     {
1293         std::wcmatch m;
1294         const wchar_t s[] = L"5%k";
1295         assert(std::regex_match(s, m, std::wregex(L"\\d[\\W]k")));
1296         assert(m.size() == 1);
1297         assert(!m.prefix().matched);
1298         assert(m.prefix().first == s);
1299         assert(m.prefix().second == m[0].first);
1300         assert(!m.suffix().matched);
1301         assert(m.suffix().first == m[0].second);
1302         assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s));
1303         assert(m.length(0) >= 0 && static_cast<size_t>(m.length(0)) == std::char_traits<wchar_t>::length(s));
1304         assert(m.position(0) == 0);
1305         assert(m.str(0) == s);
1306     }
1307 
1308   return 0;
1309 }
1310