1 //===----------------------------------------------------------------------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is dual licensed under the MIT and the University of Illinois Open 6 // Source Licenses. See LICENSE.TXT for details. 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 22 #include "test_iterators.h" 23 24 int main() 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) == 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) == 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) == 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) == 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) == 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) == 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 const char s[] = "tournament"; 368 assert(!std::regex_match(s, m, std::regex("tour|to|tournament"))); 369 assert(m.size() == 0); 370 } 371 { 372 std::cmatch m; 373 const char s[] = "tournamenttotour"; 374 assert(!std::regex_match(s, m, std::regex("(tour|to|tournament)+", 375 std::regex_constants::nosubs))); 376 assert(m.size() == 0); 377 } 378 { 379 std::cmatch m; 380 const char s[] = "ttotour"; 381 assert(std::regex_match(s, m, std::regex("(tour|to|t)+"))); 382 assert(m.size() == 2); 383 assert(!m.prefix().matched); 384 assert(m.prefix().first == s); 385 assert(m.prefix().second == m[0].first); 386 assert(!m.suffix().matched); 387 assert(m.suffix().first == m[0].second); 388 assert(m.suffix().second == m[0].second); 389 assert(m.length(0) == std::char_traits<char>::length(s)); 390 assert(m.position(0) == 0); 391 assert(m.str(0) == s); 392 assert(m.length(1) == 4); 393 assert(m.position(1) == 3); 394 assert(m.str(1) == "tour"); 395 } 396 { 397 std::cmatch m; 398 const char s[] = "-ab,ab-"; 399 assert(!std::regex_match(s, m, std::regex("-(.*),\1-"))); 400 assert(m.size() == 0); 401 } 402 { 403 std::cmatch m; 404 const char s[] = "-ab,ab-"; 405 assert(std::regex_match(s, m, std::regex("-.*,.*-"))); 406 assert(m.size() == 1); 407 assert(!m.prefix().matched); 408 assert(m.prefix().first == s); 409 assert(m.prefix().second == m[0].first); 410 assert(!m.suffix().matched); 411 assert(m.suffix().first == m[0].second); 412 assert(m.suffix().second == m[0].second); 413 assert(m.length(0) == std::char_traits<char>::length(s)); 414 assert(m.position(0) == 0); 415 assert(m.str(0) == s); 416 } 417 { 418 std::cmatch m; 419 const char s[] = "a"; 420 assert(std::regex_match(s, m, std::regex("^[a]$"))); 421 assert(m.size() == 1); 422 assert(!m.prefix().matched); 423 assert(m.prefix().first == s); 424 assert(m.prefix().second == m[0].first); 425 assert(!m.suffix().matched); 426 assert(m.suffix().first == m[0].second); 427 assert(m.suffix().second == m[0].second); 428 assert(m.length(0) == 1); 429 assert(m.position(0) == 0); 430 assert(m.str(0) == "a"); 431 } 432 { 433 std::cmatch m; 434 const char s[] = "a"; 435 assert(std::regex_match(s, m, std::regex("^[ab]$"))); 436 assert(m.size() == 1); 437 assert(!m.prefix().matched); 438 assert(m.prefix().first == s); 439 assert(m.prefix().second == m[0].first); 440 assert(!m.suffix().matched); 441 assert(m.suffix().first == m[0].second); 442 assert(m.suffix().second == m[0].second); 443 assert(m.length(0) == 1); 444 assert(m.position(0) == 0); 445 assert(m.str(0) == "a"); 446 } 447 { 448 std::cmatch m; 449 const char s[] = "c"; 450 assert(std::regex_match(s, m, std::regex("^[a-f]$"))); 451 assert(m.size() == 1); 452 assert(!m.prefix().matched); 453 assert(m.prefix().first == s); 454 assert(m.prefix().second == m[0].first); 455 assert(!m.suffix().matched); 456 assert(m.suffix().first == m[0].second); 457 assert(m.suffix().second == m[0].second); 458 assert(m.length(0) == 1); 459 assert(m.position(0) == 0); 460 assert(m.str(0) == s); 461 } 462 { 463 std::cmatch m; 464 const char s[] = "g"; 465 assert(!std::regex_match(s, m, std::regex("^[a-f]$"))); 466 assert(m.size() == 0); 467 } 468 { 469 std::cmatch m; 470 const char s[] = "Iraqi"; 471 assert(!std::regex_match(s, m, std::regex("q[^u]"))); 472 assert(m.size() == 0); 473 } 474 { 475 std::cmatch m; 476 const char s[] = "Iraq"; 477 assert(!std::regex_match(s, m, std::regex("q[^u]"))); 478 assert(m.size() == 0); 479 } 480 { 481 std::cmatch m; 482 const char s[] = "AmB"; 483 assert(std::regex_match(s, m, std::regex("A[[:lower:]]B"))); 484 assert(m.size() == 1); 485 assert(!m.prefix().matched); 486 assert(m.prefix().first == s); 487 assert(m.prefix().second == m[0].first); 488 assert(!m.suffix().matched); 489 assert(m.suffix().first == m[0].second); 490 assert(m.suffix().second == m[0].second); 491 assert(m.length(0) == std::char_traits<char>::length(s)); 492 assert(m.position(0) == 0); 493 assert(m.str(0) == s); 494 } 495 { 496 std::cmatch m; 497 const char s[] = "AMB"; 498 assert(!std::regex_match(s, m, std::regex("A[[:lower:]]B"))); 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) == 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[] = "A5B"; 525 assert(!std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B"))); 526 assert(m.size() == 0); 527 } 528 { 529 std::cmatch m; 530 const char s[] = "A?B"; 531 assert(std::regex_match(s, m, std::regex("A[^[:lower:]0-9]B"))); 532 assert(m.size() == 1); 533 assert(!m.prefix().matched); 534 assert(m.prefix().first == s); 535 assert(m.prefix().second == m[0].first); 536 assert(!m.suffix().matched); 537 assert(m.suffix().first == m[0].second); 538 assert(m.suffix().second == m[0].second); 539 assert(m.length(0) == std::char_traits<char>::length(s)); 540 assert(m.position(0) == 0); 541 assert(m.str(0) == s); 542 } 543 { 544 std::cmatch m; 545 const char s[] = "-"; 546 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]"))); 547 assert(m.size() == 1); 548 assert(!m.prefix().matched); 549 assert(m.prefix().first == s); 550 assert(m.prefix().second == m[0].first); 551 assert(!m.suffix().matched); 552 assert(m.suffix().first == m[0].second); 553 assert(m.suffix().second == m[0].second); 554 assert(m.length(0) == std::char_traits<char>::length(s)); 555 assert(m.position(0) == 0); 556 assert(m.str(0) == s); 557 } 558 { 559 std::cmatch m; 560 const char s[] = "z"; 561 assert(std::regex_match(s, m, std::regex("[a[.hyphen.]z]"))); 562 assert(m.size() == 1); 563 assert(!m.prefix().matched); 564 assert(m.prefix().first == s); 565 assert(m.prefix().second == m[0].first); 566 assert(!m.suffix().matched); 567 assert(m.suffix().first == m[0].second); 568 assert(m.suffix().second == m[0].second); 569 assert(m.length(0) == std::char_traits<char>::length(s)); 570 assert(m.position(0) == 0); 571 assert(m.str(0) == s); 572 } 573 { 574 std::cmatch m; 575 const char s[] = "m"; 576 assert(!std::regex_match(s, m, std::regex("[a[.hyphen.]z]"))); 577 assert(m.size() == 0); 578 } 579 std::locale::global(std::locale("cs_CZ.ISO8859-2")); 580 { 581 std::cmatch m; 582 const char s[] = "m"; 583 assert(std::regex_match(s, m, std::regex("[a[=M=]z]"))); 584 assert(m.size() == 1); 585 assert(!m.prefix().matched); 586 assert(m.prefix().first == s); 587 assert(m.prefix().second == m[0].first); 588 assert(!m.suffix().matched); 589 assert(m.suffix().first == m[0].second); 590 assert(m.suffix().second == m[0].second); 591 assert(m.length(0) == std::char_traits<char>::length(s)); 592 assert(m.position(0) == 0); 593 assert(m.str(0) == s); 594 } 595 { 596 std::cmatch m; 597 const char s[] = "Ch"; 598 assert(std::regex_match(s, m, std::regex("[a[.ch.]z]", 599 std::regex_constants::icase))); 600 assert(m.size() == 1); 601 assert(!m.prefix().matched); 602 assert(m.prefix().first == s); 603 assert(m.prefix().second == m[0].first); 604 assert(!m.suffix().matched); 605 assert(m.suffix().first == m[0].second); 606 assert(m.suffix().second == m[0].second); 607 assert(m.length(0) == std::char_traits<char>::length(s)); 608 assert(m.position(0) == 0); 609 assert(m.str(0) == s); 610 } 611 std::locale::global(std::locale("C")); 612 { 613 std::cmatch m; 614 const char s[] = "m"; 615 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]"))); 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 std::cmatch m; 626 const char s[] = "01a45cef9"; 627 assert(!std::regex_match(s, m, std::regex("[ace1-9]+"))); 628 assert(m.size() == 0); 629 } 630 { 631 const char r[] = "^[-+]?[0-9]+[CF]$"; 632 std::ptrdiff_t sr = std::char_traits<char>::length(r); 633 typedef forward_iterator<const char*> FI; 634 typedef bidirectional_iterator<const char*> BI; 635 std::regex regex(FI(r), FI(r+sr)); 636 std::match_results<BI> m; 637 const char s[] = "-40C"; 638 std::ptrdiff_t ss = std::char_traits<char>::length(s); 639 assert(std::regex_match(BI(s), BI(s+ss), m, regex)); 640 assert(m.size() == 1); 641 assert(!m.prefix().matched); 642 assert(m.prefix().first == BI(s)); 643 assert(m.prefix().second == m[0].first); 644 assert(!m.suffix().matched); 645 assert(m.suffix().first == m[0].second); 646 assert(m.suffix().second == m[0].second); 647 assert(m.length(0) == 4); 648 assert(m.position(0) == 0); 649 assert(m.str(0) == s); 650 } 651 { 652 std::cmatch m; 653 const char s[] = "Jeff Jeffs "; 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[] = "Jeffs Jeff"; 660 assert(!std::regex_match(s, m, std::regex("Jeff(?!s\\b)"))); 661 assert(m.size() == 0); 662 } 663 { 664 std::cmatch m; 665 const char s[] = "5%k"; 666 assert(std::regex_match(s, m, std::regex("\\d[\\W]k"))); 667 assert(m.size() == 1); 668 assert(!m.prefix().matched); 669 assert(m.prefix().first == s); 670 assert(m.prefix().second == m[0].first); 671 assert(!m.suffix().matched); 672 assert(m.suffix().first == m[0].second); 673 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 674 assert(m.length(0) == std::char_traits<char>::length(s)); 675 assert(m.position(0) == 0); 676 assert(m.str(0) == s); 677 } 678 679 { 680 std::wcmatch m; 681 const wchar_t s[] = L"a"; 682 assert(std::regex_match(s, m, std::wregex(L"a"))); 683 assert(m.size() == 1); 684 assert(!m.empty()); 685 assert(!m.prefix().matched); 686 assert(m.prefix().first == s); 687 assert(m.prefix().second == m[0].first); 688 assert(!m.suffix().matched); 689 assert(m.suffix().first == m[0].second); 690 assert(m.suffix().second == s+1); 691 assert(m.length(0) == 1); 692 assert(m.position(0) == 0); 693 assert(m.str(0) == L"a"); 694 } 695 { 696 std::wcmatch m; 697 const wchar_t s[] = L"ab"; 698 assert(std::regex_match(s, m, std::wregex(L"ab"))); 699 assert(m.size() == 1); 700 assert(!m.prefix().matched); 701 assert(m.prefix().first == s); 702 assert(m.prefix().second == m[0].first); 703 assert(!m.suffix().matched); 704 assert(m.suffix().first == m[0].second); 705 assert(m.suffix().second == s+2); 706 assert(m.length(0) == 2); 707 assert(m.position(0) == 0); 708 assert(m.str(0) == L"ab"); 709 } 710 { 711 std::wcmatch m; 712 const wchar_t s[] = L"ab"; 713 assert(!std::regex_match(s, m, std::wregex(L"ba"))); 714 assert(m.size() == 0); 715 assert(m.empty()); 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 assert(m.size() == 0); 722 } 723 { 724 std::wcmatch m; 725 const wchar_t s[] = L"aab"; 726 assert(!std::regex_match(s, m, std::wregex(L"ab"), 727 std::regex_constants::match_continuous)); 728 assert(m.size() == 0); 729 } 730 { 731 std::wcmatch m; 732 const wchar_t s[] = L"abcd"; 733 assert(!std::regex_match(s, m, std::wregex(L"bc"))); 734 assert(m.size() == 0); 735 } 736 { 737 std::wcmatch m; 738 const wchar_t s[] = L"abbc"; 739 assert(std::regex_match(s, m, std::wregex(L"ab*c"))); 740 assert(m.size() == 1); 741 assert(!m.prefix().matched); 742 assert(m.prefix().first == s); 743 assert(m.prefix().second == m[0].first); 744 assert(!m.suffix().matched); 745 assert(m.suffix().first == m[0].second); 746 assert(m.suffix().second == s+4); 747 assert(m.length(0) == 4); 748 assert(m.position(0) == 0); 749 assert(m.str(0) == s); 750 } 751 { 752 std::wcmatch m; 753 const wchar_t s[] = L"ababc"; 754 assert(std::regex_match(s, m, std::wregex(L"(ab)*c"))); 755 assert(m.size() == 2); 756 assert(!m.prefix().matched); 757 assert(m.prefix().first == s); 758 assert(m.prefix().second == m[0].first); 759 assert(!m.suffix().matched); 760 assert(m.suffix().first == m[0].second); 761 assert(m.suffix().second == s+5); 762 assert(m.length(0) == 5); 763 assert(m.position(0) == 0); 764 assert(m.str(0) == s); 765 assert(m.length(1) == 2); 766 assert(m.position(1) == 2); 767 assert(m.str(1) == L"ab"); 768 } 769 { 770 std::wcmatch m; 771 const wchar_t s[] = L"abcdefghijk"; 772 assert(!std::regex_match(s, m, std::wregex(L"cd((e)fg)hi"))); 773 assert(m.size() == 0); 774 } 775 { 776 std::wcmatch m; 777 const wchar_t s[] = L"abc"; 778 assert(std::regex_match(s, m, std::wregex(L"^abc"))); 779 assert(m.size() == 1); 780 assert(!m.prefix().matched); 781 assert(m.prefix().first == s); 782 assert(m.prefix().second == m[0].first); 783 assert(!m.suffix().matched); 784 assert(m.suffix().first == m[0].second); 785 assert(m.suffix().second == s+3); 786 assert(m.length(0) == 3); 787 assert(m.position(0) == 0); 788 assert(m.str(0) == s); 789 } 790 { 791 std::wcmatch m; 792 const wchar_t s[] = L"abcd"; 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"aabc"; 799 assert(!std::regex_match(s, m, std::wregex(L"^abc"))); 800 assert(m.size() == 0); 801 } 802 { 803 std::wcmatch m; 804 const wchar_t s[] = L"abc"; 805 assert(std::regex_match(s, m, std::wregex(L"abc$"))); 806 assert(m.size() == 1); 807 assert(!m.prefix().matched); 808 assert(m.prefix().first == s); 809 assert(m.prefix().second == m[0].first); 810 assert(!m.suffix().matched); 811 assert(m.suffix().first == m[0].second); 812 assert(m.suffix().second == s+3); 813 assert(m.length(0) == 3); 814 assert(m.position(0) == 0); 815 assert(m.str(0) == s); 816 } 817 { 818 std::wcmatch m; 819 const wchar_t s[] = L"efabc"; 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"efabcg"; 826 assert(!std::regex_match(s, m, std::wregex(L"abc$"))); 827 assert(m.size() == 0); 828 } 829 { 830 std::wcmatch m; 831 const wchar_t s[] = L"abc"; 832 assert(std::regex_match(s, m, std::wregex(L"a.c"))); 833 assert(m.size() == 1); 834 assert(!m.prefix().matched); 835 assert(m.prefix().first == s); 836 assert(m.prefix().second == m[0].first); 837 assert(!m.suffix().matched); 838 assert(m.suffix().first == m[0].second); 839 assert(m.suffix().second == s+3); 840 assert(m.length(0) == 3); 841 assert(m.position(0) == 0); 842 assert(m.str(0) == s); 843 } 844 { 845 std::wcmatch m; 846 const wchar_t s[] = L"acc"; 847 assert(std::regex_match(s, m, std::wregex(L"a.c"))); 848 assert(m.size() == 1); 849 assert(!m.prefix().matched); 850 assert(m.prefix().first == s); 851 assert(m.prefix().second == m[0].first); 852 assert(!m.suffix().matched); 853 assert(m.suffix().first == m[0].second); 854 assert(m.suffix().second == s+3); 855 assert(m.length(0) == 3); 856 assert(m.position(0) == 0); 857 assert(m.str(0) == s); 858 } 859 { 860 std::wcmatch m; 861 const wchar_t s[] = L"acc"; 862 assert(std::regex_match(s, m, std::wregex(L"a.c"))); 863 assert(m.size() == 1); 864 assert(!m.prefix().matched); 865 assert(m.prefix().first == s); 866 assert(m.prefix().second == m[0].first); 867 assert(!m.suffix().matched); 868 assert(m.suffix().first == m[0].second); 869 assert(m.suffix().second == s+3); 870 assert(m.length(0) == 3); 871 assert(m.position(0) == 0); 872 assert(m.str(0) == s); 873 } 874 { 875 std::wcmatch m; 876 const wchar_t s[] = L"abcdef"; 877 assert(std::regex_match(s, m, std::wregex(L"(.*).*"))); 878 assert(m.size() == 2); 879 assert(!m.prefix().matched); 880 assert(m.prefix().first == s); 881 assert(m.prefix().second == m[0].first); 882 assert(!m.suffix().matched); 883 assert(m.suffix().first == m[0].second); 884 assert(m.suffix().second == s+6); 885 assert(m.length(0) == 6); 886 assert(m.position(0) == 0); 887 assert(m.str(0) == s); 888 assert(m.length(1) == 6); 889 assert(m.position(1) == 0); 890 assert(m.str(1) == s); 891 } 892 { 893 std::wcmatch m; 894 const wchar_t s[] = L"bc"; 895 assert(!std::regex_match(s, m, std::wregex(L"(a*)*"))); 896 assert(m.size() == 0); 897 } 898 { 899 std::wcmatch m; 900 const wchar_t s[] = L"abbc"; 901 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 902 assert(m.size() == 0); 903 } 904 { 905 std::wcmatch m; 906 const wchar_t s[] = L"abbbc"; 907 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 908 assert(m.size() == 1); 909 assert(!m.prefix().matched); 910 assert(m.prefix().first == s); 911 assert(m.prefix().second == m[0].first); 912 assert(!m.suffix().matched); 913 assert(m.suffix().first == m[0].second); 914 assert(m.suffix().second == m[0].second); 915 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 916 assert(m.position(0) == 0); 917 assert(m.str(0) == s); 918 } 919 { 920 std::wcmatch m; 921 const wchar_t s[] = L"abbbbc"; 922 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 923 assert(m.size() == 1); 924 assert(!m.prefix().matched); 925 assert(m.prefix().first == s); 926 assert(m.prefix().second == m[0].first); 927 assert(!m.suffix().matched); 928 assert(m.suffix().first == m[0].second); 929 assert(m.suffix().second == m[0].second); 930 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 931 assert(m.position(0) == 0); 932 assert(m.str(0) == s); 933 } 934 { 935 std::wcmatch m; 936 const wchar_t s[] = L"abbbbbc"; 937 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 938 assert(m.size() == 1); 939 assert(!m.prefix().matched); 940 assert(m.prefix().first == s); 941 assert(m.prefix().second == m[0].first); 942 assert(!m.suffix().matched); 943 assert(m.suffix().first == m[0].second); 944 assert(m.suffix().second == m[0].second); 945 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 946 assert(m.position(0) == 0); 947 assert(m.str(0) == s); 948 } 949 { 950 std::wcmatch m; 951 const wchar_t s[] = L"adefc"; 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"abbbbbbc"; 958 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 959 assert(m.size() == 0); 960 } 961 { 962 std::wcmatch m; 963 const wchar_t s[] = L"adec"; 964 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 965 assert(m.size() == 0); 966 } 967 { 968 std::wcmatch m; 969 const wchar_t s[] = L"adefc"; 970 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 971 assert(m.size() == 1); 972 assert(!m.prefix().matched); 973 assert(m.prefix().first == s); 974 assert(m.prefix().second == m[0].first); 975 assert(!m.suffix().matched); 976 assert(m.suffix().first == m[0].second); 977 assert(m.suffix().second == m[0].second); 978 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 979 assert(m.position(0) == 0); 980 assert(m.str(0) == s); 981 } 982 { 983 std::wcmatch m; 984 const wchar_t s[] = L"adefgc"; 985 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 986 assert(m.size() == 1); 987 assert(!m.prefix().matched); 988 assert(m.prefix().first == s); 989 assert(m.prefix().second == m[0].first); 990 assert(!m.suffix().matched); 991 assert(m.suffix().first == m[0].second); 992 assert(m.suffix().second == m[0].second); 993 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 994 assert(m.position(0) == 0); 995 assert(m.str(0) == s); 996 } 997 { 998 std::wcmatch m; 999 const wchar_t s[] = L"adefghc"; 1000 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 1001 assert(m.size() == 1); 1002 assert(!m.prefix().matched); 1003 assert(m.prefix().first == s); 1004 assert(m.prefix().second == m[0].first); 1005 assert(!m.suffix().matched); 1006 assert(m.suffix().first == m[0].second); 1007 assert(m.suffix().second == m[0].second); 1008 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1009 assert(m.position(0) == 0); 1010 assert(m.str(0) == s); 1011 } 1012 { 1013 std::wcmatch m; 1014 const wchar_t s[] = L"adefghic"; 1015 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 1016 assert(m.size() == 0); 1017 } 1018 { 1019 std::wcmatch m; 1020 const wchar_t s[] = L"tournament"; 1021 assert(!std::regex_match(s, m, std::wregex(L"tour|to|tournament"))); 1022 assert(m.size() == 0); 1023 } 1024 { 1025 std::wcmatch m; 1026 const wchar_t s[] = L"tournamenttotour"; 1027 assert(!std::regex_match(s, m, std::wregex(L"(tour|to|tournament)+", 1028 std::regex_constants::nosubs))); 1029 assert(m.size() == 0); 1030 } 1031 { 1032 std::wcmatch m; 1033 const wchar_t s[] = L"ttotour"; 1034 assert(std::regex_match(s, m, std::wregex(L"(tour|to|t)+"))); 1035 assert(m.size() == 2); 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) == std::char_traits<wchar_t>::length(s)); 1043 assert(m.position(0) == 0); 1044 assert(m.str(0) == s); 1045 assert(m.length(1) == 4); 1046 assert(m.position(1) == 3); 1047 assert(m.str(1) == L"tour"); 1048 } 1049 { 1050 std::wcmatch m; 1051 const wchar_t s[] = L"-ab,ab-"; 1052 assert(!std::regex_match(s, m, std::wregex(L"-(.*),\1-"))); 1053 assert(m.size() == 0); 1054 } 1055 { 1056 std::wcmatch m; 1057 const wchar_t s[] = L"-ab,ab-"; 1058 assert(std::regex_match(s, m, std::wregex(L"-.*,.*-"))); 1059 assert(m.size() == 1); 1060 assert(!m.prefix().matched); 1061 assert(m.prefix().first == s); 1062 assert(m.prefix().second == m[0].first); 1063 assert(!m.suffix().matched); 1064 assert(m.suffix().first == m[0].second); 1065 assert(m.suffix().second == m[0].second); 1066 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1067 assert(m.position(0) == 0); 1068 assert(m.str(0) == s); 1069 } 1070 { 1071 std::wcmatch m; 1072 const wchar_t s[] = L"a"; 1073 assert(std::regex_match(s, m, std::wregex(L"^[a]$"))); 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) == 1); 1082 assert(m.position(0) == 0); 1083 assert(m.str(0) == L"a"); 1084 } 1085 { 1086 std::wcmatch m; 1087 const wchar_t s[] = L"a"; 1088 assert(std::regex_match(s, m, std::wregex(L"^[ab]$"))); 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"c"; 1103 assert(std::regex_match(s, m, std::wregex(L"^[a-f]$"))); 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) == s); 1114 } 1115 { 1116 std::wcmatch m; 1117 const wchar_t s[] = L"g"; 1118 assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$"))); 1119 assert(m.size() == 0); 1120 } 1121 { 1122 std::wcmatch m; 1123 const wchar_t s[] = L"Iraqi"; 1124 assert(!std::regex_match(s, m, std::wregex(L"q[^u]"))); 1125 assert(m.size() == 0); 1126 } 1127 { 1128 std::wcmatch m; 1129 const wchar_t s[] = L"Iraq"; 1130 assert(!std::regex_match(s, m, std::wregex(L"q[^u]"))); 1131 assert(m.size() == 0); 1132 } 1133 { 1134 std::wcmatch m; 1135 const wchar_t s[] = L"AmB"; 1136 assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B"))); 1137 assert(m.size() == 1); 1138 assert(!m.prefix().matched); 1139 assert(m.prefix().first == s); 1140 assert(m.prefix().second == m[0].first); 1141 assert(!m.suffix().matched); 1142 assert(m.suffix().first == m[0].second); 1143 assert(m.suffix().second == m[0].second); 1144 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1145 assert(m.position(0) == 0); 1146 assert(m.str(0) == s); 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() == 0); 1153 } 1154 { 1155 std::wcmatch m; 1156 const wchar_t s[] = L"AMB"; 1157 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B"))); 1158 assert(m.size() == 1); 1159 assert(!m.prefix().matched); 1160 assert(m.prefix().first == s); 1161 assert(m.prefix().second == m[0].first); 1162 assert(!m.suffix().matched); 1163 assert(m.suffix().first == m[0].second); 1164 assert(m.suffix().second == m[0].second); 1165 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1166 assert(m.position(0) == 0); 1167 assert(m.str(0) == s); 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() == 0); 1174 } 1175 { 1176 std::wcmatch m; 1177 const wchar_t s[] = L"A5B"; 1178 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B"))); 1179 assert(m.size() == 0); 1180 } 1181 { 1182 std::wcmatch m; 1183 const wchar_t s[] = L"A?B"; 1184 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B"))); 1185 assert(m.size() == 1); 1186 assert(!m.prefix().matched); 1187 assert(m.prefix().first == s); 1188 assert(m.prefix().second == m[0].first); 1189 assert(!m.suffix().matched); 1190 assert(m.suffix().first == m[0].second); 1191 assert(m.suffix().second == m[0].second); 1192 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1193 assert(m.position(0) == 0); 1194 assert(m.str(0) == s); 1195 } 1196 { 1197 std::wcmatch m; 1198 const wchar_t s[] = L"-"; 1199 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]"))); 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) == 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"z"; 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) == 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"m"; 1229 assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]"))); 1230 assert(m.size() == 0); 1231 } 1232 std::locale::global(std::locale("cs_CZ.ISO8859-2")); 1233 { 1234 std::wcmatch m; 1235 const wchar_t s[] = L"m"; 1236 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]"))); 1237 assert(m.size() == 1); 1238 assert(!m.prefix().matched); 1239 assert(m.prefix().first == s); 1240 assert(m.prefix().second == m[0].first); 1241 assert(!m.suffix().matched); 1242 assert(m.suffix().first == m[0].second); 1243 assert(m.suffix().second == m[0].second); 1244 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1245 assert(m.position(0) == 0); 1246 assert(m.str(0) == s); 1247 } 1248 { 1249 std::wcmatch m; 1250 const wchar_t s[] = L"Ch"; 1251 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]", 1252 std::regex_constants::icase))); 1253 assert(m.size() == 1); 1254 assert(!m.prefix().matched); 1255 assert(m.prefix().first == s); 1256 assert(m.prefix().second == m[0].first); 1257 assert(!m.suffix().matched); 1258 assert(m.suffix().first == m[0].second); 1259 assert(m.suffix().second == m[0].second); 1260 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1261 assert(m.position(0) == 0); 1262 assert(m.str(0) == s); 1263 } 1264 std::locale::global(std::locale("C")); 1265 { 1266 std::wcmatch m; 1267 const wchar_t s[] = L"m"; 1268 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]"))); 1269 assert(m.size() == 0); 1270 } 1271 { 1272 std::wcmatch m; 1273 const wchar_t s[] = L"01a45cef9"; 1274 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*"))); 1275 assert(m.size() == 0); 1276 } 1277 { 1278 std::wcmatch m; 1279 const wchar_t s[] = L"01a45cef9"; 1280 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]+"))); 1281 assert(m.size() == 0); 1282 } 1283 { 1284 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$"; 1285 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r); 1286 typedef forward_iterator<const wchar_t*> FI; 1287 typedef bidirectional_iterator<const wchar_t*> BI; 1288 std::wregex regex(FI(r), FI(r+sr)); 1289 std::match_results<BI> m; 1290 const wchar_t s[] = L"-40C"; 1291 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s); 1292 assert(std::regex_match(BI(s), BI(s+ss), m, regex)); 1293 assert(m.size() == 1); 1294 assert(!m.prefix().matched); 1295 assert(m.prefix().first == BI(s)); 1296 assert(m.prefix().second == m[0].first); 1297 assert(!m.suffix().matched); 1298 assert(m.suffix().first == m[0].second); 1299 assert(m.suffix().second == m[0].second); 1300 assert(m.length(0) == 4); 1301 assert(m.position(0) == 0); 1302 assert(m.str(0) == s); 1303 } 1304 { 1305 std::wcmatch m; 1306 const wchar_t s[] = L"Jeff Jeffs "; 1307 assert(!std::regex_match(s, m, std::wregex(L"Jeff(?=s\\b)"))); 1308 assert(m.size() == 0); 1309 } 1310 { 1311 std::wcmatch m; 1312 const wchar_t s[] = L"Jeffs Jeff"; 1313 assert(!std::regex_match(s, m, std::wregex(L"Jeff(?!s\\b)"))); 1314 assert(m.size() == 0); 1315 } 1316 { 1317 std::wcmatch m; 1318 const wchar_t s[] = L"5%k"; 1319 assert(std::regex_match(s, m, std::wregex(L"\\d[\\W]k"))); 1320 assert(m.size() == 1); 1321 assert(!m.prefix().matched); 1322 assert(m.prefix().first == s); 1323 assert(m.prefix().second == m[0].first); 1324 assert(!m.suffix().matched); 1325 assert(m.suffix().first == m[0].second); 1326 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1327 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1328 assert(m.position(0) == 0); 1329 assert(m.str(0) == s); 1330 } 1331 } 1332