@@ -10375,4 +10375,124 @@ No match
10375
10375
BBAAAAAACC
10376
10376
0: AAAAAA
10377
10377
10378
+ # This pattern validates regular expression patterns. The original that I was
10379
+ # sent was this:
10380
+ # /^((?:(?:[^?+*{}()[\]\\|]+|\\.|\[(?:\^?\\.|\^[^\\]|[^\\^])(?:[^\]\\]+|\\.)*\]|\((?:\?[:=!]|\?<[=!]|\?>)?(?1)??\)|\(\?(?:R|[+-]?\d+)\))(?:(?:[?+*]|\{\d+(?:,\d*)?\})[?+]?)?|\|)*)$/
10381
+ # This is not very readable, and also does not handle all features. I have done
10382
+ # some work on it.
10383
+
10384
+ /^
10385
+ (?<re>
10386
+ # A regular expression is zero or more of these items.
10387
+ (?:
10388
+ # An item is one of these:
10389
+ (?:
10390
+ [^?+*{}()\[\]\\|]++| # Non-meta characters or unquoted .
10391
+ \\.| # Quoted .
10392
+
10393
+ \[ # Class, which is [
10394
+ (?: # Followed by
10395
+ \^?\\.| # Optional ^ and any escaped character
10396
+ \^[^\\]| # OR ^ and not escaped character
10397
+ [^\\^] # OR neither ^ nor \
10398
+ ) # Followed by
10399
+ (?:[^\]\\]+|\\.)*+ # Zero or more (not ] or \) OR escaped dot
10400
+ \]| # Class ends with ]
10401
+
10402
+ \( # Parenthesized group
10403
+ (?: # Start with optional
10404
+ \?[:=!]| # ? followed by : = !
10405
+ \?<[=!]| # OR ?< followed by = or !
10406
+ \?> # OR ?>
10407
+ )?
10408
+ (?&re)?? # Then a nested <re>
10409
+ \)| # End parenthesized group
10410
+
10411
+ \(\? # Other parenthesized items
10412
+ (?: # (? followed by
10413
+ R| # R
10414
+ [+-]?\d++ # Or optional +- and digits
10415
+ )
10416
+ \)| # End parens
10417
+
10418
+ \(\* # Verbs
10419
+ (?:
10420
+ COMMIT|
10421
+ FAIL|
10422
+ MARK:[^)]*|
10423
+ (?:PRUNE|SKIP|THEN)(?::[^\)]*+)?
10424
+ )
10425
+ \)
10426
+ ) # End list of items
10427
+
10428
+ # Followed by an optional quantifier
10429
+
10430
+ (?:
10431
+ (?:
10432
+ [?+*] # ?+*
10433
+ | # OR
10434
+ \{\d+ # { digits
10435
+ (?:,\d*)? # optionally followed by ,digits
10436
+ \} # then closing }
10437
+ | # OR
10438
+ \{,\d+} # {,digits}
10439
+ )
10440
+ [?+]? # optional ungreedy or possessive
10441
+ )?
10442
+
10443
+ | # OR an "item" is a branch ending
10444
+
10445
+ \|
10446
+
10447
+ )* # Zero or more top-level items.
10448
+ ) # End regex group.
10449
+ $/x
10450
+ [abcdef]
10451
+ 0: [abcdef]
10452
+ 1: [abcdef]
10453
+ [abc\\]def]
10454
+ 0: [abc\]def]
10455
+ 1: [abc\]def]
10456
+ a.b|abcd
10457
+ 0: a.b|abcd
10458
+ 1: a.b|abcd
10459
+ ab()d
10460
+ 0: ab()d
10461
+ 1: ab()d
10462
+ ab{1,3}d
10463
+ 0: ab{1,3}d
10464
+ 1: ab{1,3}d
10465
+ ab{,3}d
10466
+ 0: ab{,3}d
10467
+ 1: ab{,3}d
10468
+ ab(*FAIL)d(*COMMIT)(*SKIP)(*THEN:abc)
10469
+ 0: ab(*FAIL)d(*COMMIT)(*SKIP)(*THEN:abc)
10470
+ 1: ab(*FAIL)d(*COMMIT)(*SKIP)(*THEN:abc)
10471
+ ab(*MARK:xyz)
10472
+ 0: ab(*MARK:xyz)
10473
+ 1: ab(*MARK:xyz)
10474
+ (?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[,;:])(?=.{8,16})(?!.*[\\s])
10475
+ 0: (?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[,;:])(?=.{8,16})(?!.*[\s])
10476
+ 1: (?=.*[A-Z])(?=.*[a-z])(?=.*[0-9])(?=.*[,;:])(?=.{8,16})(?!.*[\s])
10477
+ abcd\\t\\n\\r\\f\\a\\e\\071\\x3b\\^\\\\\\?caxyz
10478
+ 0: abcd\t\n\r\f\a\e\071\x3b\^\\\?caxyz
10479
+ 1: abcd\t\n\r\f\a\e\071\x3b\^\\\?caxyz
10480
+ a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz
10481
+ 0: a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz
10482
+ 1: a*abc?xyz+pqr{3}ab{2,}xy{4,5}pq{0,6}AB{0,}zz
10483
+ \\G(?:(?=(\\1.|)(.))){1,13}?(?!.*\\2.*\\2)\\1\\K\\2
10484
+ 0: \G(?:(?=(\1.|)(.))){1,13}?(?!.*\2.*\2)\1\K\2
10485
+ 1: \G(?:(?=(\1.|)(.))){1,13}?(?!.*\2.*\2)\1\K\2
10486
+ \= Expect no match
10487
+ ab)d
10488
+ No match
10489
+ ab(d
10490
+ No match
10491
+ {4,5}
10492
+ No match
10493
+ a[]b
10494
+ No match
10495
+ (a)(?(1)a|b|c)
10496
+ No match
10497
+
10378
10498
# End of testinput1
0 commit comments