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 { 612 std::cmatch m; 613 const char s[] = "foobar"; 614 assert(std::regex_match(s, m, std::regex("[^\\0]*"))); 615 assert(m.size() == 1); 616 } 617 { 618 std::cmatch m; 619 const char s[] = "foo\0bar"; 620 assert(std::regex_match(s, s+7, m, std::regex("[abfor\\0]*"))); 621 assert(m.size() == 1); 622 } 623 std::locale::global(std::locale("C")); 624 { 625 std::cmatch m; 626 const char s[] = "m"; 627 assert(!std::regex_match(s, m, std::regex("[a[=M=]z]"))); 628 assert(m.size() == 0); 629 } 630 { 631 std::cmatch m; 632 const char s[] = "01a45cef9"; 633 assert(!std::regex_match(s, m, std::regex("[ace1-9]*"))); 634 assert(m.size() == 0); 635 } 636 { 637 std::cmatch m; 638 const char s[] = "01a45cef9"; 639 assert(!std::regex_match(s, m, std::regex("[ace1-9]+"))); 640 assert(m.size() == 0); 641 } 642 { 643 const char r[] = "^[-+]?[0-9]+[CF]$"; 644 std::ptrdiff_t sr = std::char_traits<char>::length(r); 645 typedef forward_iterator<const char*> FI; 646 typedef bidirectional_iterator<const char*> BI; 647 std::regex regex(FI(r), FI(r+sr)); 648 std::match_results<BI> m; 649 const char s[] = "-40C"; 650 std::ptrdiff_t ss = std::char_traits<char>::length(s); 651 assert(std::regex_match(BI(s), BI(s+ss), m, regex)); 652 assert(m.size() == 1); 653 assert(!m.prefix().matched); 654 assert(m.prefix().first == BI(s)); 655 assert(m.prefix().second == m[0].first); 656 assert(!m.suffix().matched); 657 assert(m.suffix().first == m[0].second); 658 assert(m.suffix().second == m[0].second); 659 assert(m.length(0) == 4); 660 assert(m.position(0) == 0); 661 assert(m.str(0) == s); 662 } 663 { 664 std::cmatch m; 665 const char s[] = "Jeff Jeffs "; 666 assert(!std::regex_match(s, m, std::regex("Jeff(?=s\\b)"))); 667 assert(m.size() == 0); 668 } 669 { 670 std::cmatch m; 671 const char s[] = "Jeffs Jeff"; 672 assert(!std::regex_match(s, m, std::regex("Jeff(?!s\\b)"))); 673 assert(m.size() == 0); 674 } 675 { 676 std::cmatch m; 677 const char s[] = "5%k"; 678 assert(std::regex_match(s, m, std::regex("\\d[\\W]k"))); 679 assert(m.size() == 1); 680 assert(!m.prefix().matched); 681 assert(m.prefix().first == s); 682 assert(m.prefix().second == m[0].first); 683 assert(!m.suffix().matched); 684 assert(m.suffix().first == m[0].second); 685 assert(m.suffix().second == s + std::char_traits<char>::length(s)); 686 assert(m.length(0) == std::char_traits<char>::length(s)); 687 assert(m.position(0) == 0); 688 assert(m.str(0) == s); 689 } 690 691 { 692 std::wcmatch m; 693 const wchar_t s[] = L"a"; 694 assert(std::regex_match(s, m, std::wregex(L"a"))); 695 assert(m.size() == 1); 696 assert(!m.empty()); 697 assert(!m.prefix().matched); 698 assert(m.prefix().first == s); 699 assert(m.prefix().second == m[0].first); 700 assert(!m.suffix().matched); 701 assert(m.suffix().first == m[0].second); 702 assert(m.suffix().second == s+1); 703 assert(m.length(0) == 1); 704 assert(m.position(0) == 0); 705 assert(m.str(0) == L"a"); 706 } 707 { 708 std::wcmatch m; 709 const wchar_t s[] = L"ab"; 710 assert(std::regex_match(s, m, std::wregex(L"ab"))); 711 assert(m.size() == 1); 712 assert(!m.prefix().matched); 713 assert(m.prefix().first == s); 714 assert(m.prefix().second == m[0].first); 715 assert(!m.suffix().matched); 716 assert(m.suffix().first == m[0].second); 717 assert(m.suffix().second == s+2); 718 assert(m.length(0) == 2); 719 assert(m.position(0) == 0); 720 assert(m.str(0) == L"ab"); 721 } 722 { 723 std::wcmatch m; 724 const wchar_t s[] = L"ab"; 725 assert(!std::regex_match(s, m, std::wregex(L"ba"))); 726 assert(m.size() == 0); 727 assert(m.empty()); 728 } 729 { 730 std::wcmatch m; 731 const wchar_t s[] = L"aab"; 732 assert(!std::regex_match(s, m, std::wregex(L"ab"))); 733 assert(m.size() == 0); 734 } 735 { 736 std::wcmatch m; 737 const wchar_t s[] = L"aab"; 738 assert(!std::regex_match(s, m, std::wregex(L"ab"), 739 std::regex_constants::match_continuous)); 740 assert(m.size() == 0); 741 } 742 { 743 std::wcmatch m; 744 const wchar_t s[] = L"abcd"; 745 assert(!std::regex_match(s, m, std::wregex(L"bc"))); 746 assert(m.size() == 0); 747 } 748 { 749 std::wcmatch m; 750 const wchar_t s[] = L"abbc"; 751 assert(std::regex_match(s, m, std::wregex(L"ab*c"))); 752 assert(m.size() == 1); 753 assert(!m.prefix().matched); 754 assert(m.prefix().first == s); 755 assert(m.prefix().second == m[0].first); 756 assert(!m.suffix().matched); 757 assert(m.suffix().first == m[0].second); 758 assert(m.suffix().second == s+4); 759 assert(m.length(0) == 4); 760 assert(m.position(0) == 0); 761 assert(m.str(0) == s); 762 } 763 { 764 std::wcmatch m; 765 const wchar_t s[] = L"ababc"; 766 assert(std::regex_match(s, m, std::wregex(L"(ab)*c"))); 767 assert(m.size() == 2); 768 assert(!m.prefix().matched); 769 assert(m.prefix().first == s); 770 assert(m.prefix().second == m[0].first); 771 assert(!m.suffix().matched); 772 assert(m.suffix().first == m[0].second); 773 assert(m.suffix().second == s+5); 774 assert(m.length(0) == 5); 775 assert(m.position(0) == 0); 776 assert(m.str(0) == s); 777 assert(m.length(1) == 2); 778 assert(m.position(1) == 2); 779 assert(m.str(1) == L"ab"); 780 } 781 { 782 std::wcmatch m; 783 const wchar_t s[] = L"abcdefghijk"; 784 assert(!std::regex_match(s, m, std::wregex(L"cd((e)fg)hi"))); 785 assert(m.size() == 0); 786 } 787 { 788 std::wcmatch m; 789 const wchar_t s[] = L"abc"; 790 assert(std::regex_match(s, m, std::wregex(L"^abc"))); 791 assert(m.size() == 1); 792 assert(!m.prefix().matched); 793 assert(m.prefix().first == s); 794 assert(m.prefix().second == m[0].first); 795 assert(!m.suffix().matched); 796 assert(m.suffix().first == m[0].second); 797 assert(m.suffix().second == s+3); 798 assert(m.length(0) == 3); 799 assert(m.position(0) == 0); 800 assert(m.str(0) == s); 801 } 802 { 803 std::wcmatch m; 804 const wchar_t s[] = L"abcd"; 805 assert(!std::regex_match(s, m, std::wregex(L"^abc"))); 806 assert(m.size() == 0); 807 } 808 { 809 std::wcmatch m; 810 const wchar_t s[] = L"aabc"; 811 assert(!std::regex_match(s, m, std::wregex(L"^abc"))); 812 assert(m.size() == 0); 813 } 814 { 815 std::wcmatch m; 816 const wchar_t s[] = L"abc"; 817 assert(std::regex_match(s, m, std::wregex(L"abc$"))); 818 assert(m.size() == 1); 819 assert(!m.prefix().matched); 820 assert(m.prefix().first == s); 821 assert(m.prefix().second == m[0].first); 822 assert(!m.suffix().matched); 823 assert(m.suffix().first == m[0].second); 824 assert(m.suffix().second == s+3); 825 assert(m.length(0) == 3); 826 assert(m.position(0) == 0); 827 assert(m.str(0) == s); 828 } 829 { 830 std::wcmatch m; 831 const wchar_t s[] = L"efabc"; 832 assert(!std::regex_match(s, m, std::wregex(L"abc$"))); 833 assert(m.size() == 0); 834 } 835 { 836 std::wcmatch m; 837 const wchar_t s[] = L"efabcg"; 838 assert(!std::regex_match(s, m, std::wregex(L"abc$"))); 839 assert(m.size() == 0); 840 } 841 { 842 std::wcmatch m; 843 const wchar_t s[] = L"abc"; 844 assert(std::regex_match(s, m, std::wregex(L"a.c"))); 845 assert(m.size() == 1); 846 assert(!m.prefix().matched); 847 assert(m.prefix().first == s); 848 assert(m.prefix().second == m[0].first); 849 assert(!m.suffix().matched); 850 assert(m.suffix().first == m[0].second); 851 assert(m.suffix().second == s+3); 852 assert(m.length(0) == 3); 853 assert(m.position(0) == 0); 854 assert(m.str(0) == s); 855 } 856 { 857 std::wcmatch m; 858 const wchar_t s[] = L"acc"; 859 assert(std::regex_match(s, m, std::wregex(L"a.c"))); 860 assert(m.size() == 1); 861 assert(!m.prefix().matched); 862 assert(m.prefix().first == s); 863 assert(m.prefix().second == m[0].first); 864 assert(!m.suffix().matched); 865 assert(m.suffix().first == m[0].second); 866 assert(m.suffix().second == s+3); 867 assert(m.length(0) == 3); 868 assert(m.position(0) == 0); 869 assert(m.str(0) == s); 870 } 871 { 872 std::wcmatch m; 873 const wchar_t s[] = L"acc"; 874 assert(std::regex_match(s, m, std::wregex(L"a.c"))); 875 assert(m.size() == 1); 876 assert(!m.prefix().matched); 877 assert(m.prefix().first == s); 878 assert(m.prefix().second == m[0].first); 879 assert(!m.suffix().matched); 880 assert(m.suffix().first == m[0].second); 881 assert(m.suffix().second == s+3); 882 assert(m.length(0) == 3); 883 assert(m.position(0) == 0); 884 assert(m.str(0) == s); 885 } 886 { 887 std::wcmatch m; 888 const wchar_t s[] = L"abcdef"; 889 assert(std::regex_match(s, m, std::wregex(L"(.*).*"))); 890 assert(m.size() == 2); 891 assert(!m.prefix().matched); 892 assert(m.prefix().first == s); 893 assert(m.prefix().second == m[0].first); 894 assert(!m.suffix().matched); 895 assert(m.suffix().first == m[0].second); 896 assert(m.suffix().second == s+6); 897 assert(m.length(0) == 6); 898 assert(m.position(0) == 0); 899 assert(m.str(0) == s); 900 assert(m.length(1) == 6); 901 assert(m.position(1) == 0); 902 assert(m.str(1) == s); 903 } 904 { 905 std::wcmatch m; 906 const wchar_t s[] = L"bc"; 907 assert(!std::regex_match(s, m, std::wregex(L"(a*)*"))); 908 assert(m.size() == 0); 909 } 910 { 911 std::wcmatch m; 912 const wchar_t s[] = L"abbc"; 913 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 914 assert(m.size() == 0); 915 } 916 { 917 std::wcmatch m; 918 const wchar_t s[] = L"abbbc"; 919 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 920 assert(m.size() == 1); 921 assert(!m.prefix().matched); 922 assert(m.prefix().first == s); 923 assert(m.prefix().second == m[0].first); 924 assert(!m.suffix().matched); 925 assert(m.suffix().first == m[0].second); 926 assert(m.suffix().second == m[0].second); 927 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 928 assert(m.position(0) == 0); 929 assert(m.str(0) == s); 930 } 931 { 932 std::wcmatch m; 933 const wchar_t s[] = L"abbbbc"; 934 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 935 assert(m.size() == 1); 936 assert(!m.prefix().matched); 937 assert(m.prefix().first == s); 938 assert(m.prefix().second == m[0].first); 939 assert(!m.suffix().matched); 940 assert(m.suffix().first == m[0].second); 941 assert(m.suffix().second == m[0].second); 942 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 943 assert(m.position(0) == 0); 944 assert(m.str(0) == s); 945 } 946 { 947 std::wcmatch m; 948 const wchar_t s[] = L"abbbbbc"; 949 assert(std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 950 assert(m.size() == 1); 951 assert(!m.prefix().matched); 952 assert(m.prefix().first == s); 953 assert(m.prefix().second == m[0].first); 954 assert(!m.suffix().matched); 955 assert(m.suffix().first == m[0].second); 956 assert(m.suffix().second == m[0].second); 957 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 958 assert(m.position(0) == 0); 959 assert(m.str(0) == s); 960 } 961 { 962 std::wcmatch m; 963 const wchar_t s[] = L"adefc"; 964 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 965 assert(m.size() == 0); 966 } 967 { 968 std::wcmatch m; 969 const wchar_t s[] = L"abbbbbbc"; 970 assert(!std::regex_match(s, m, std::wregex(L"ab{3,5}c"))); 971 assert(m.size() == 0); 972 } 973 { 974 std::wcmatch m; 975 const wchar_t s[] = L"adec"; 976 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 977 assert(m.size() == 0); 978 } 979 { 980 std::wcmatch m; 981 const wchar_t s[] = L"adefc"; 982 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 983 assert(m.size() == 1); 984 assert(!m.prefix().matched); 985 assert(m.prefix().first == s); 986 assert(m.prefix().second == m[0].first); 987 assert(!m.suffix().matched); 988 assert(m.suffix().first == m[0].second); 989 assert(m.suffix().second == m[0].second); 990 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 991 assert(m.position(0) == 0); 992 assert(m.str(0) == s); 993 } 994 { 995 std::wcmatch m; 996 const wchar_t s[] = L"adefgc"; 997 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 998 assert(m.size() == 1); 999 assert(!m.prefix().matched); 1000 assert(m.prefix().first == s); 1001 assert(m.prefix().second == m[0].first); 1002 assert(!m.suffix().matched); 1003 assert(m.suffix().first == m[0].second); 1004 assert(m.suffix().second == m[0].second); 1005 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1006 assert(m.position(0) == 0); 1007 assert(m.str(0) == s); 1008 } 1009 { 1010 std::wcmatch m; 1011 const wchar_t s[] = L"adefghc"; 1012 assert(std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 1013 assert(m.size() == 1); 1014 assert(!m.prefix().matched); 1015 assert(m.prefix().first == s); 1016 assert(m.prefix().second == m[0].first); 1017 assert(!m.suffix().matched); 1018 assert(m.suffix().first == m[0].second); 1019 assert(m.suffix().second == m[0].second); 1020 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1021 assert(m.position(0) == 0); 1022 assert(m.str(0) == s); 1023 } 1024 { 1025 std::wcmatch m; 1026 const wchar_t s[] = L"adefghic"; 1027 assert(!std::regex_match(s, m, std::wregex(L"a.{3,5}c"))); 1028 assert(m.size() == 0); 1029 } 1030 { 1031 std::wcmatch m; 1032 const wchar_t s[] = L"tournament"; 1033 assert(!std::regex_match(s, m, std::wregex(L"tour|to|tournament"))); 1034 assert(m.size() == 0); 1035 } 1036 { 1037 std::wcmatch m; 1038 const wchar_t s[] = L"tournamenttotour"; 1039 assert(!std::regex_match(s, m, std::wregex(L"(tour|to|tournament)+", 1040 std::regex_constants::nosubs))); 1041 assert(m.size() == 0); 1042 } 1043 { 1044 std::wcmatch m; 1045 const wchar_t s[] = L"ttotour"; 1046 assert(std::regex_match(s, m, std::wregex(L"(tour|to|t)+"))); 1047 assert(m.size() == 2); 1048 assert(!m.prefix().matched); 1049 assert(m.prefix().first == s); 1050 assert(m.prefix().second == m[0].first); 1051 assert(!m.suffix().matched); 1052 assert(m.suffix().first == m[0].second); 1053 assert(m.suffix().second == m[0].second); 1054 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1055 assert(m.position(0) == 0); 1056 assert(m.str(0) == s); 1057 assert(m.length(1) == 4); 1058 assert(m.position(1) == 3); 1059 assert(m.str(1) == L"tour"); 1060 } 1061 { 1062 std::wcmatch m; 1063 const wchar_t s[] = L"-ab,ab-"; 1064 assert(!std::regex_match(s, m, std::wregex(L"-(.*),\1-"))); 1065 assert(m.size() == 0); 1066 } 1067 { 1068 std::wcmatch m; 1069 const wchar_t s[] = L"-ab,ab-"; 1070 assert(std::regex_match(s, m, std::wregex(L"-.*,.*-"))); 1071 assert(m.size() == 1); 1072 assert(!m.prefix().matched); 1073 assert(m.prefix().first == s); 1074 assert(m.prefix().second == m[0].first); 1075 assert(!m.suffix().matched); 1076 assert(m.suffix().first == m[0].second); 1077 assert(m.suffix().second == m[0].second); 1078 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1079 assert(m.position(0) == 0); 1080 assert(m.str(0) == s); 1081 } 1082 { 1083 std::wcmatch m; 1084 const wchar_t s[] = L"a"; 1085 assert(std::regex_match(s, m, std::wregex(L"^[a]$"))); 1086 assert(m.size() == 1); 1087 assert(!m.prefix().matched); 1088 assert(m.prefix().first == s); 1089 assert(m.prefix().second == m[0].first); 1090 assert(!m.suffix().matched); 1091 assert(m.suffix().first == m[0].second); 1092 assert(m.suffix().second == m[0].second); 1093 assert(m.length(0) == 1); 1094 assert(m.position(0) == 0); 1095 assert(m.str(0) == L"a"); 1096 } 1097 { 1098 std::wcmatch m; 1099 const wchar_t s[] = L"a"; 1100 assert(std::regex_match(s, m, std::wregex(L"^[ab]$"))); 1101 assert(m.size() == 1); 1102 assert(!m.prefix().matched); 1103 assert(m.prefix().first == s); 1104 assert(m.prefix().second == m[0].first); 1105 assert(!m.suffix().matched); 1106 assert(m.suffix().first == m[0].second); 1107 assert(m.suffix().second == m[0].second); 1108 assert(m.length(0) == 1); 1109 assert(m.position(0) == 0); 1110 assert(m.str(0) == L"a"); 1111 } 1112 { 1113 std::wcmatch m; 1114 const wchar_t s[] = L"c"; 1115 assert(std::regex_match(s, m, std::wregex(L"^[a-f]$"))); 1116 assert(m.size() == 1); 1117 assert(!m.prefix().matched); 1118 assert(m.prefix().first == s); 1119 assert(m.prefix().second == m[0].first); 1120 assert(!m.suffix().matched); 1121 assert(m.suffix().first == m[0].second); 1122 assert(m.suffix().second == m[0].second); 1123 assert(m.length(0) == 1); 1124 assert(m.position(0) == 0); 1125 assert(m.str(0) == s); 1126 } 1127 { 1128 std::wcmatch m; 1129 const wchar_t s[] = L"g"; 1130 assert(!std::regex_match(s, m, std::wregex(L"^[a-f]$"))); 1131 assert(m.size() == 0); 1132 } 1133 { 1134 std::wcmatch m; 1135 const wchar_t s[] = L"Iraqi"; 1136 assert(!std::regex_match(s, m, std::wregex(L"q[^u]"))); 1137 assert(m.size() == 0); 1138 } 1139 { 1140 std::wcmatch m; 1141 const wchar_t s[] = L"Iraq"; 1142 assert(!std::regex_match(s, m, std::wregex(L"q[^u]"))); 1143 assert(m.size() == 0); 1144 } 1145 { 1146 std::wcmatch m; 1147 const wchar_t s[] = L"AmB"; 1148 assert(std::regex_match(s, m, std::wregex(L"A[[:lower:]]B"))); 1149 assert(m.size() == 1); 1150 assert(!m.prefix().matched); 1151 assert(m.prefix().first == s); 1152 assert(m.prefix().second == m[0].first); 1153 assert(!m.suffix().matched); 1154 assert(m.suffix().first == m[0].second); 1155 assert(m.suffix().second == m[0].second); 1156 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1157 assert(m.position(0) == 0); 1158 assert(m.str(0) == s); 1159 } 1160 { 1161 std::wcmatch m; 1162 const wchar_t s[] = L"AMB"; 1163 assert(!std::regex_match(s, m, std::wregex(L"A[[:lower:]]B"))); 1164 assert(m.size() == 0); 1165 } 1166 { 1167 std::wcmatch m; 1168 const wchar_t s[] = L"AMB"; 1169 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B"))); 1170 assert(m.size() == 1); 1171 assert(!m.prefix().matched); 1172 assert(m.prefix().first == s); 1173 assert(m.prefix().second == m[0].first); 1174 assert(!m.suffix().matched); 1175 assert(m.suffix().first == m[0].second); 1176 assert(m.suffix().second == m[0].second); 1177 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1178 assert(m.position(0) == 0); 1179 assert(m.str(0) == s); 1180 } 1181 { 1182 std::wcmatch m; 1183 const wchar_t s[] = L"AmB"; 1184 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]]B"))); 1185 assert(m.size() == 0); 1186 } 1187 { 1188 std::wcmatch m; 1189 const wchar_t s[] = L"A5B"; 1190 assert(!std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B"))); 1191 assert(m.size() == 0); 1192 } 1193 { 1194 std::wcmatch m; 1195 const wchar_t s[] = L"A?B"; 1196 assert(std::regex_match(s, m, std::wregex(L"A[^[:lower:]0-9]B"))); 1197 assert(m.size() == 1); 1198 assert(!m.prefix().matched); 1199 assert(m.prefix().first == s); 1200 assert(m.prefix().second == m[0].first); 1201 assert(!m.suffix().matched); 1202 assert(m.suffix().first == m[0].second); 1203 assert(m.suffix().second == m[0].second); 1204 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1205 assert(m.position(0) == 0); 1206 assert(m.str(0) == s); 1207 } 1208 { 1209 std::wcmatch m; 1210 const wchar_t s[] = L"-"; 1211 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]"))); 1212 assert(m.size() == 1); 1213 assert(!m.prefix().matched); 1214 assert(m.prefix().first == s); 1215 assert(m.prefix().second == m[0].first); 1216 assert(!m.suffix().matched); 1217 assert(m.suffix().first == m[0].second); 1218 assert(m.suffix().second == m[0].second); 1219 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1220 assert(m.position(0) == 0); 1221 assert(m.str(0) == s); 1222 } 1223 { 1224 std::wcmatch m; 1225 const wchar_t s[] = L"z"; 1226 assert(std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]"))); 1227 assert(m.size() == 1); 1228 assert(!m.prefix().matched); 1229 assert(m.prefix().first == s); 1230 assert(m.prefix().second == m[0].first); 1231 assert(!m.suffix().matched); 1232 assert(m.suffix().first == m[0].second); 1233 assert(m.suffix().second == m[0].second); 1234 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1235 assert(m.position(0) == 0); 1236 assert(m.str(0) == s); 1237 } 1238 { 1239 std::wcmatch m; 1240 const wchar_t s[] = L"m"; 1241 assert(!std::regex_match(s, m, std::wregex(L"[a[.hyphen.]z]"))); 1242 assert(m.size() == 0); 1243 } 1244 std::locale::global(std::locale("cs_CZ.ISO8859-2")); 1245 { 1246 std::wcmatch m; 1247 const wchar_t s[] = L"m"; 1248 assert(std::regex_match(s, m, std::wregex(L"[a[=M=]z]"))); 1249 assert(m.size() == 1); 1250 assert(!m.prefix().matched); 1251 assert(m.prefix().first == s); 1252 assert(m.prefix().second == m[0].first); 1253 assert(!m.suffix().matched); 1254 assert(m.suffix().first == m[0].second); 1255 assert(m.suffix().second == m[0].second); 1256 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1257 assert(m.position(0) == 0); 1258 assert(m.str(0) == s); 1259 } 1260 { 1261 std::wcmatch m; 1262 const wchar_t s[] = L"Ch"; 1263 assert(std::regex_match(s, m, std::wregex(L"[a[.ch.]z]", 1264 std::regex_constants::icase))); 1265 assert(m.size() == 1); 1266 assert(!m.prefix().matched); 1267 assert(m.prefix().first == s); 1268 assert(m.prefix().second == m[0].first); 1269 assert(!m.suffix().matched); 1270 assert(m.suffix().first == m[0].second); 1271 assert(m.suffix().second == m[0].second); 1272 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1273 assert(m.position(0) == 0); 1274 assert(m.str(0) == s); 1275 } 1276 std::locale::global(std::locale("C")); 1277 { 1278 std::wcmatch m; 1279 const wchar_t s[] = L"m"; 1280 assert(!std::regex_match(s, m, std::wregex(L"[a[=M=]z]"))); 1281 assert(m.size() == 0); 1282 } 1283 { 1284 std::wcmatch m; 1285 const wchar_t s[] = L"01a45cef9"; 1286 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]*"))); 1287 assert(m.size() == 0); 1288 } 1289 { 1290 std::wcmatch m; 1291 const wchar_t s[] = L"01a45cef9"; 1292 assert(!std::regex_match(s, m, std::wregex(L"[ace1-9]+"))); 1293 assert(m.size() == 0); 1294 } 1295 { 1296 const wchar_t r[] = L"^[-+]?[0-9]+[CF]$"; 1297 std::ptrdiff_t sr = std::char_traits<wchar_t>::length(r); 1298 typedef forward_iterator<const wchar_t*> FI; 1299 typedef bidirectional_iterator<const wchar_t*> BI; 1300 std::wregex regex(FI(r), FI(r+sr)); 1301 std::match_results<BI> m; 1302 const wchar_t s[] = L"-40C"; 1303 std::ptrdiff_t ss = std::char_traits<wchar_t>::length(s); 1304 assert(std::regex_match(BI(s), BI(s+ss), m, regex)); 1305 assert(m.size() == 1); 1306 assert(!m.prefix().matched); 1307 assert(m.prefix().first == BI(s)); 1308 assert(m.prefix().second == m[0].first); 1309 assert(!m.suffix().matched); 1310 assert(m.suffix().first == m[0].second); 1311 assert(m.suffix().second == m[0].second); 1312 assert(m.length(0) == 4); 1313 assert(m.position(0) == 0); 1314 assert(m.str(0) == s); 1315 } 1316 { 1317 std::wcmatch m; 1318 const wchar_t s[] = L"Jeff Jeffs "; 1319 assert(!std::regex_match(s, m, std::wregex(L"Jeff(?=s\\b)"))); 1320 assert(m.size() == 0); 1321 } 1322 { 1323 std::wcmatch m; 1324 const wchar_t s[] = L"Jeffs Jeff"; 1325 assert(!std::regex_match(s, m, std::wregex(L"Jeff(?!s\\b)"))); 1326 assert(m.size() == 0); 1327 } 1328 { 1329 std::wcmatch m; 1330 const wchar_t s[] = L"5%k"; 1331 assert(std::regex_match(s, m, std::wregex(L"\\d[\\W]k"))); 1332 assert(m.size() == 1); 1333 assert(!m.prefix().matched); 1334 assert(m.prefix().first == s); 1335 assert(m.prefix().second == m[0].first); 1336 assert(!m.suffix().matched); 1337 assert(m.suffix().first == m[0].second); 1338 assert(m.suffix().second == s + std::char_traits<wchar_t>::length(s)); 1339 assert(m.length(0) == std::char_traits<wchar_t>::length(s)); 1340 assert(m.position(0) == 0); 1341 assert(m.str(0) == s); 1342 } 1343 } 1344