3428 "yyy"); |
3428 "yyy"); |
3429 |
3429 |
3430 //replaceFirst/All |
3430 //replaceFirst/All |
3431 checkReplaceFirst("(?<gn>ab)(c*)", |
3431 checkReplaceFirst("(?<gn>ab)(c*)", |
3432 "abccczzzabcczzzabccc", |
3432 "abccczzzabcczzzabccc", |
3433 "$<gn>", |
3433 "${gn}", |
3434 "abzzzabcczzzabccc"); |
3434 "abzzzabcczzzabccc"); |
3435 |
3435 |
3436 checkReplaceAll("(?<gn>ab)(c*)", |
3436 checkReplaceAll("(?<gn>ab)(c*)", |
3437 "abccczzzabcczzzabccc", |
3437 "abccczzzabcczzzabccc", |
3438 "$<gn>", |
3438 "${gn}", |
3439 "abzzzabzzzab"); |
3439 "abzzzabzzzab"); |
3440 |
3440 |
3441 |
3441 |
3442 checkReplaceFirst("(?<gn>ab)(c*)", |
3442 checkReplaceFirst("(?<gn>ab)(c*)", |
3443 "zzzabccczzzabcczzzabccczzz", |
3443 "zzzabccczzzabcczzzabccczzz", |
3444 "$<gn>", |
3444 "${gn}", |
3445 "zzzabzzzabcczzzabccczzz"); |
3445 "zzzabzzzabcczzzabccczzz"); |
3446 |
3446 |
3447 checkReplaceAll("(?<gn>ab)(c*)", |
3447 checkReplaceAll("(?<gn>ab)(c*)", |
3448 "zzzabccczzzabcczzzabccczzz", |
3448 "zzzabccczzzabcczzzabccczzz", |
3449 "$<gn>", |
3449 "${gn}", |
3450 "zzzabzzzabzzzabzzz"); |
3450 "zzzabzzzabzzzabzzz"); |
3451 |
3451 |
3452 checkReplaceFirst("(?<gn1>ab)(?<gn2>c*)", |
3452 checkReplaceFirst("(?<gn1>ab)(?<gn2>c*)", |
3453 "zzzabccczzzabcczzzabccczzz", |
3453 "zzzabccczzzabcczzzabccczzz", |
3454 "$<gn2>", |
3454 "${gn2}", |
3455 "zzzccczzzabcczzzabccczzz"); |
3455 "zzzccczzzabcczzzabccczzz"); |
3456 |
3456 |
3457 checkReplaceAll("(?<gn1>ab)(?<gn2>c*)", |
3457 checkReplaceAll("(?<gn1>ab)(?<gn2>c*)", |
3458 "zzzabccczzzabcczzzabccczzz", |
3458 "zzzabccczzzabcczzzabccczzz", |
3459 "$<gn2>", |
3459 "${gn2}", |
3460 "zzzccczzzcczzzccczzz"); |
3460 "zzzccczzzcczzzccczzz"); |
3461 |
3461 |
3462 //toSupplementaries("(ab)(c*)")); |
3462 //toSupplementaries("(ab)(c*)")); |
3463 checkReplaceFirst("(?<gn1>" + toSupplementaries("ab") + |
3463 checkReplaceFirst("(?<gn1>" + toSupplementaries("ab") + |
3464 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3464 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3465 toSupplementaries("abccczzzabcczzzabccc"), |
3465 toSupplementaries("abccczzzabcczzzabccc"), |
3466 "$<gn1>", |
3466 "${gn1}", |
3467 toSupplementaries("abzzzabcczzzabccc")); |
3467 toSupplementaries("abzzzabcczzzabccc")); |
3468 |
3468 |
3469 |
3469 |
3470 checkReplaceAll("(?<gn1>" + toSupplementaries("ab") + |
3470 checkReplaceAll("(?<gn1>" + toSupplementaries("ab") + |
3471 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3471 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3472 toSupplementaries("abccczzzabcczzzabccc"), |
3472 toSupplementaries("abccczzzabcczzzabccc"), |
3473 "$<gn1>", |
3473 "${gn1}", |
3474 toSupplementaries("abzzzabzzzab")); |
3474 toSupplementaries("abzzzabzzzab")); |
3475 |
3475 |
3476 checkReplaceFirst("(?<gn1>" + toSupplementaries("ab") + |
3476 checkReplaceFirst("(?<gn1>" + toSupplementaries("ab") + |
3477 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3477 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3478 toSupplementaries("abccczzzabcczzzabccc"), |
3478 toSupplementaries("abccczzzabcczzzabccc"), |
3479 "$<gn2>", |
3479 "${gn2}", |
3480 toSupplementaries("ccczzzabcczzzabccc")); |
3480 toSupplementaries("ccczzzabcczzzabccc")); |
3481 |
3481 |
3482 |
3482 |
3483 checkReplaceAll("(?<gn1>" + toSupplementaries("ab") + |
3483 checkReplaceAll("(?<gn1>" + toSupplementaries("ab") + |
3484 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3484 ")(?<gn2>" + toSupplementaries("c") + "*)", |
3485 toSupplementaries("abccczzzabcczzzabccc"), |
3485 toSupplementaries("abccczzzabcczzzabccc"), |
3486 "$<gn2>", |
3486 "${gn2}", |
3487 toSupplementaries("ccczzzcczzzccc")); |
3487 toSupplementaries("ccczzzcczzzccc")); |
3488 |
3488 |
3489 checkReplaceFirst("(?<dog>Dog)AndCat", |
3489 checkReplaceFirst("(?<dog>Dog)AndCat", |
3490 "zzzDogAndCatzzzDogAndCatzzz", |
3490 "zzzDogAndCatzzzDogAndCatzzz", |
3491 "$<dog>", |
3491 "${dog}", |
3492 "zzzDogzzzDogAndCatzzz"); |
3492 "zzzDogzzzDogAndCatzzz"); |
3493 |
3493 |
3494 |
3494 |
3495 checkReplaceAll("(?<dog>Dog)AndCat", |
3495 checkReplaceAll("(?<dog>Dog)AndCat", |
3496 "zzzDogAndCatzzzDogAndCatzzz", |
3496 "zzzDogAndCatzzzDogAndCatzzz", |
3497 "$<dog>", |
3497 "${dog}", |
3498 "zzzDogzzzDogzzz"); |
3498 "zzzDogzzzDogzzz"); |
3499 |
3499 |
3500 // backref in Matcher & String |
3500 // backref in Matcher & String |
3501 if (!"abcdefghij".replaceFirst("cd(?<gn>ef)gh", "$<gn>").equals("abefij") || |
3501 if (!"abcdefghij".replaceFirst("cd(?<gn>ef)gh", "${gn}").equals("abefij") || |
3502 !"abbbcbdbefgh".replaceAll("(?<gn>[a-e])b", "$<gn>").equals("abcdefgh")) |
3502 !"abbbcbdbefgh".replaceAll("(?<gn>[a-e])b", "${gn}").equals("abcdefgh")) |
3503 failCount++; |
3503 failCount++; |
3504 |
3504 |
3505 // negative |
3505 // negative |
3506 checkExpectedFail("(?<groupnamehasnoascii.in>abc)(def)"); |
3506 checkExpectedFail("(?<groupnamehasnoascii.in>abc)(def)"); |
3507 checkExpectedFail("(?<groupnamehasnoascii_in>abc)(def)"); |
3507 checkExpectedFail("(?<groupnamehasnoascii_in>abc)(def)"); |
|
3508 checkExpectedFail("(?<6groupnamestartswithdigit>abc)(def)"); |
3508 checkExpectedFail("(?<gname>abc)(def)\\k<gnameX>"); |
3509 checkExpectedFail("(?<gname>abc)(def)\\k<gnameX>"); |
3509 checkExpectedFail("(?<gname>abc)(?<gname>def)\\k<gnameX>"); |
3510 checkExpectedFail("(?<gname>abc)(?<gname>def)\\k<gnameX>"); |
3510 checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"), |
3511 checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"), |
3511 "gnameX"); |
3512 "gnameX"); |
3512 checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"), |
3513 checkExpectedFail(Pattern.compile("(?<gname>abc)(def)").matcher("abcdef"), |