# A Different Kind of Meta Regex Golf

Notice: Following popular demand I have slightly relaxed the rules:

• The maximum regex size grows by 1 byte every 5 answers. Answer N may use up to 29 + ⌈N/5⌉ bytes.
• The score of each answer will be (M/(30+N/5))N

In regex golf, you're given two sets of strings, and are asked to create the shortest regex which matches all strings in the first set, but fails on all strings in the second set.

That is what we're going to do, but each time someone answers, their regex itself will be added to one of the two sets of strings (of their own choice). Therefore, there is a strict order to answers in this challenge.

Let's go through an example:

• Say I start this with abc (which I won't), and put it in the match set.
• Then a valid second answer would be a, as it matches the above (and there are no strings that need to fail yet). Say this answer goes in the fail set.
• Now the third answer has to match abc but fail on a. A possible third answer is therefore b. Let's put this in the match set.
• The fourth answer now has to match abc and b, but fail on a. We'll disallow duplicate answers, so a valid regex would be c|b.

What's important is that your answer should be as short as possible. This may be trivial for the first few answers, but once we get a few answers, it should get harder and harder to get the desired match in as few characters as possible.

For the actual challenge, initially the match set contains PPCG and the fail set contains [PPCG], and I have already provided the first answer.

There should never be two answers with the same N. If two people happen to simultaneously answer for some N, the one who answered later (even if it's a few seconds difference) should graciously delete their answer.

To make this run a bit smoother, try to stick to the following steps when posting your answer:

• Make sure that someone has independently verified the correctness of the previous answer (and left a corresponding comment).
• Take the two test sets found in the previous answer, and write a regex which matches all strings in one set and none in the other.

# N. [regex flavour] - [regex size in bytes]

[regex]

[notes, explanation, observations, whatever]

### The next answer has to match the following strings:

[match set]

### And fail on these strings:

[fail set]


where N is the number of your answer. Please copy [match set] and [fail set] from the previous answer, and append your regex to one of them.

This is absolutely vital to the challenge! I've provided a dashboard tool for the challenge to help with the bookkeeping, and it relies on the above template. (See bottom of the post.)

These regulations may seem rather strict, but they are necessary to avoid invalid answers somewhere up the chain.

## Rules

• A user may only submit one answer per 4 hour period. (This is to prevent users from constantly watching the question and answering as much as possible.)
• A user may not submit two answers in a row. (e.g. since I submitted answer 1 I can't do answer 2, but I could do 3.)
• Do not edit answers that have been verified. (Even if you find a way to shorten it!)
• Should a mistake be discovered earlier in the chain (i.e. after follow-up answers have been posted), the offending answer should be deleted and will be removed from the set of strings that new submissions should fail on. However, all answers that have been posted since should not be changed to reflect.
• Clearly state one flavour your regex is valid in. You may choose any flavour that is freely testable online. There's a good list of online testers over on StackOverflow. In particular, Regex101 and RegexPlanet should be useful, as they support a wide variety of flavours. Please include a link to the tester you chose in your answer. By switching on the global and multiline modifiers in the tester, you can test all strings at once, one on each line (these modifiers are not counted towards your regex size, because they aren't needed on any individual string).
• Your regex must not be empty.
• Your regex for answer N must not be longer than 29 + ⌈N/5⌉ bytes. I.e. answers 1 to 5 may use up to 30 bytes (inclusive), answers 6 to 10 may use up to 31 bytes... answers 31 to 35 may use up to 36 bytes. Check the dashboard to see how many characters the next answer may use.
• Your regex must not be identical to any string in either test set.
• Do not include delimiters in your submission or byte count, even if the relevant host language uses them. If your regex uses modifiers, add one byte per modifier to the regex size. E.g. /foo/i would be 4 bytes.

## Scoring

Each answer's score is calculated as (M/(30+N/5))N, where M is the size of the regex in bytes, and N is it's number. Each user's score is the product of all their answers. The user with the lowest overall score wins. In the unlikely event of a tie, the user with the latest submission wins. I will accept that user's latest answer.

If you prefer summing scores, you can calculate each answer's score as N * (log(M) - log(30)) and sum those up over all answers. That will give the same leaderboard order.

There is no need to include an answer's score in the answer, just report M. The challenge dashboard at the bottom of the question will compute the scores, and in the event of two very close scores, I'll double check the results using arbitrary-precision types.

Note that the score of each answer is less than 1, so you can improve your overall score by providing a new answer. However, the shorter each of your submissions, the more efficiently you can lower your score. Furthermore, later answers can achieve a lower score although being longer, due to the increasing exponent.

## Dashboard

I've written a little Dashboard tool, using Stack Snippets, based on Optimizer's work over here. I hope this will help us get some order into these answer-dependent challenges.

This will display the current status of the challenge - in particular, if there are conflicting answers, if an answer needs to be verified, or if the next answer can be posted.

It also produces a list of all answers with scores, as well as a leaderboard of all users. Please stick to the challenge format above, so the dashboard can read out the relevant strings from your answers. Otherwise you might not be included in the leaderboard.

Please let me know (ideally in chat) if you spot any bugs or have some ideas how the usefulness of the tool could be improved.

(?<!\\..)(?!]).$^[\w^]*$|!|]P|G]$!|[^?]P(CG|G..)? [^])]$|^\^?P|P.\].$([.$?]|G\])$|^\^?P|\]P ([P.?]$|[]^]P|G\]$|CG) !|((G.|P|\.)$|[^?]P|CG)$^[(!P]|G..$|]..\||[^?]P$^.{3,23}[.-~]..$|[^P?][PG] ^..(.[!G)(3w^]|.{7}|)|$\? \.\)|P[.$?]|w\^|^[^|C\\]*$|^P  ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P
([^\\}<]{3}|][^]]|^).?[$PG]$
!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P
([^\\}<]{3}|][^]]|^).?[$PG]$
(?<!\\..)(?!]).$^[\w^]*$|!|]P|G]$ ### And fail on these strings: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG ^[^\\|]*(\\\\)*[^\\|]*[^\]]  • Correctness verified. Nov 13, 2014 at 22:00 # 8. ECMAScript flavour - 14 bytes [^?][PG]|<|PG  Demo ### The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]).  ### And fail on these strings: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG  • Correctness verified. Nov 13, 2014 at 21:00 • Fixed the demo link. Nov 13, 2014 at 23:57 • @FryAmTheEggman The script does read the comments, but only looks for "correctness verified" as a substring (ignoring case). Nov 14, 2014 at 0:20 • @MartinBüttner Thanks, good to know. Nov 14, 2014 at 0:30 • +1 for singlehandedly making this challenge 10 times harder Nov 15, 2014 at 13:14 # 2. ECMAScript flavour - 6 bytes ^[P\^]  Test it here ### The next answer has to match the following strings: PPCG ^P  ### And fail on these strings: [PPCG] ^[P\^]  • Correctness verified. Nov 13, 2014 at 19:19 # 9. Python flavour - 28 ^[^\\|]*(\\\\)*[^\\|]*[^\]]  Tested on Regex101 ### The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]).  ### And fail on these strings: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG ^[^\\|]*(\\\\)*[^\\|]*[^\]]  • I also found this not to work a minute ago. It requires two backslashes in a row to match so I don't think a flag could save it. Nov 13, 2014 at 21:34 • Whoops.... Should have been a * instead of +. I edited my answer Nov 13, 2014 at 21:36 • Correctness verfied. Nov 13, 2014 at 21:37 # 23. PCRE flavour - 28 ([^\\}<]{3}|][^]]|^).?[PG]  Tested on Regex101. ### The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]). ^[\w^]*|!|]P|G]$$!|[^?]P(CG|G..)?$
[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$
([P.$?]$|[]^]P|G\]$|CG)$
!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$


### And fail on these strings:

[PPCG]
^[P\^]
[^\]]$^\^?P [^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$^(.{,4}|.{9}|.{16,19}|.{5}P)$
^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[$PG]$ • What does [^] do? Nov 14, 2014 at 12:34 • @feersum In most flavours, a ] as the first element of a character class (after optional negation), is just a ] inside the character class and doesn't close (because empty character classes are a bit pointless). So [^]] matches anything but ]. The notable exception is ECMAScript, which does allow empty character classes. In that case [] doesn't match anything, it acts like (?!) and [^] matches any character, which is convenient, because ECMAScript doesn't have an s modifier, and [\s\S] is a pain to type an read. Nov 14, 2014 at 12:37 • Correctness verified. Nov 14, 2014 at 12:37 # 11. Python - 29 ^(.{,4}|.{9}|.{16,19}|.{5}P)$


► Test at RegexPlanet

Almost all invalid answers have a different length than all the valid ones. This regex makes use of that.

### The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$(?<!\\..)(?!]).$
!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$^..(.[!G)(3w^]|.{7}$|$)|$\? \.\)|P[.?]|w\^|^[^|C\\]*|^P ^..(.[!)3G^w]|)|\^.{7}|G\)  ### And fail on these strings: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]] ^(.{,4}|.{9}|.{16,19}|.{5}P) ^[^?]*[PG]|[?].*$$
^[^[]P|]P|(G]|[.])$\..|!|\|G|^[\^P]P|P\^|G.$$...\^.P|^!|G]$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[PG] ^(..[^^].{4,22}$|[^?]+\w)$|2
^(..[^^].{4,22}$|[^?]+\w)|~ ^..(.[!()3G^w]|.{7}|)|G\\  • Correctness verified. Nov 20, 2014 at 15:03 • Nice! Barring reshuffling, that's exactly what I had Nov 20, 2014 at 19:18 • I was trying to calculate this using genetic algorithm, but it produced only 30-character regex... Now running it to get the next answer. Current result - 32 characters. – Vi. Nov 21, 2014 at 4:06 • @Vi A genetic algorithm eh, interesting ideas you have there :P Nov 21, 2014 at 5:33 • @Sp3000, Now 30 characters... But another anwser has arrived, so need to restart. – Vi. Nov 21, 2014 at 9:55 ## 31. Perl flavour - 29 [?[CP(].[-<)|w]|^P|^[^C|\\]* I don't know how it works, it was produced by my the first foray into genetic algoritms. There is program output that mentions the answer. The next answer has to match: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]). ^[\w^]*|!|]P|G]$$!|[^?]P(CG|G..)?$
[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$
([P.$?]$|[]^]P|G\]$|CG)$
!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$
^..(.[!G)(3w^]|.{7}$|$)|$\? \.\)|P[.?]|w\^|^[^|C\\]*|^P ^..(.[!)3G^w]|)|\^.{7}|G\)  and to fail: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]] ^(.{,4}|.{9}|.{16,19}|.{5}P) ^[^?]*[PG]|[?].*$$^[^[]P|]P|(G]|[.])$\..|!|\|G|^[\^P]P|P\^|G.$$
...\^.P|^!|G]$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[PG] ^(..[^^].{4,22}$|[^?]+\w)$|2 ^(..[^^].{4,22}$|[^?]+\w)|~ ^..(.[!()3G^w]|.{7}|)|G\\ [[?C(].[-!)|w]|^P|^[^C|\\]* [?[CP(].[-<)|w]|^P|^[^C|\\]*  • Correctness verified. Nov 24, 2014 at 11:35 • Ahaha nice - did you use the previous answers as seeds for the population or did it just end up looking like the previous one? Nov 24, 2014 at 12:00 • The passing and failing strings are used as initial building blocks. They hovewer got banned after some time due to being local minimums. You can see how it goes in the program log: the number in parentheses after "metric=" is the measure of how fast we are going forward. It it's low for long, we ban current answers and reset. – Vi. Nov 24, 2014 at 12:06 • (Meanwhile, 31-character candidate for next answer is already found) – Vi. Nov 24, 2014 at 12:09 • Oh, the limit increased? It's not 29? This way it is not going to end soon... I though the main challenge is to find the last, the ultimate regex. – Vi. Nov 24, 2014 at 13:01 ## 32. PCRE — 30 bytes ^..(.{7}|.[3Gw!^)]|)|G.?.?\)  Tested on Regex101 The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]). ^[\w^]*|!|]P|G]$$
!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$^..(.[!G)(3w^]|.{7}$|$)|$\? \.\)|P[.?]|w\^|^[^|C\\]*|^P ^..(.[!)3G^w]|)|\^.{7}|G\)  And fail on these strings: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]] ^(.{,4}|.{9}|.{16,19}|.{5}P) ^[^?]*[PG]|[?].*$$
^[^[]P|]P|(G]|[.])$\..|!|\|G|^[\^P]P|P\^|G.$$...\^.P|^!|G]$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[PG] ^(..[^^].{4,22}$|[^?]+\w)$|2
^(..[^^].{4,22}$|[^?]+\w)|~ ^..(.[!()3G^w]|.{7}|)|G\\ [[?C(].[-!)|w]|^P|^[^C|\\]* [?[CP(].[-<)|w]|^P|^[^C|\\]* ^..(.{7}|.[3Gw!^)]|)|G.?.?\)  • Correctness verified. Nov 24, 2014 at 13:40 • Why is it added to "fail" list? It already fails on itself, so can serve as the next answer without modifications. I suppose for each answer there is no choice of to which list it is to be appended. – Vi. Nov 24, 2014 at 14:03 • @Vi. I guess hwnd's feeling nice today Nov 24, 2014 at 14:04 • I'll make it harder as it keeps going. – hwnd Nov 24, 2014 at 14:06 # 42. Python flavour - 38 \?[^w]*$$|^P|\w.\)|w.?\+|w\^|[^?P]P$


Tested on Regex101

The lack of entropy in the last few answers was getting to me... (should have done this sooner)

### The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$(?<!\\..)(?!]).$
^[\w^]*$|!|]P|G]$!|[^?]P(CG|G..)? [^])]$|^\^?P|P.\].$
([.$?]|G\])$|^\^?P|\]P ([P.?]$|[]^]P|G\]$|CG) !|((G.|P|\.)$|[^?]P|CG)$
^[(!P]|G..$|]..\||[^?]P$
^.{3,23}[.-~]..$|[^P?][PG] ^..(.[!G)(3w^]|.{7}|)|$\?
\.\)|P[.$?]|w\^|^[^|C\\]*$|^P
^..(.[!)3G^w]|$)|\^.{7}$|G\)
\?[^w$]*$|[]^C]\w+|w\^|\|..\) \w.\)|\?[^-]*$$|[]^C]\w$|w[+^] []^C]\w$|\w.\)|-$|w[+^]|\?[^w]*$$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P
([^\\}<]{3}|][^]]|^).?[$PG]$
^(..[^^].{4,22}$|[^?]+\w)|2 ^(..[^^].{4,22}$|[^?]+\w)$|~ ^..(.[!()3G^w]|.{7}$|$)|G\\ [[?C(].[-!)|w]|^P|^[^C|\\]*$
[?[CP(].[-<)|w]|^P|^[^C|\\]*$^..(.{7}$|.[3Gw!^)]|$)|G.?.?\) ^...[3w!G)]|^[^\\C|]*$|G.?.?\)
^[^C\\|]+$|G.\)|\.\)|w\^|^P|\...?] ^P|!.3|w\^|^[^C\\|]+$|\.[)$-](?!.!) \?[^$w]*$|[]C^]\w|w.]|\w.\)$..\\|\?[^w$]*$|w\^|[]^C]\w []^C]\w|\w.\)|w[[+^]|\?[^w]*$$
!|[^?]P(CG|G..)?$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P

• Correctness verified. (And yes, that's right, the previous 22 is now invalid.) Nov 14, 2014 at 11:00

# 26. Python flavor - 28

^..(.[!G)(3w^]|.{7}$|$)|$\?  Test on Regex101 ### The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]). ^[\w^]*|!|]P|G]$$!|[^?]P(CG|G..)?$
[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$
([P.$?]$|[]^]P|G\]$|CG)$
!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$
!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$^..(.[!G)(3w^]|.{7}$|$)|$\? \.\)|P[.?]|w\^|^[^|C\\]*|^P ^..(.[!)3G^w]|)|\^.{7}|G\)  ### And fail on these strings: [PPCG] ^[P\^] [^\]] ^\^?P [^?][PG]|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]] ^(.{,4}|.{9}|.{16,19}|.{5}P) ^[^?]*[PG]|[?].*$$
^[^[]P|]P|(G]|[.])$\..|!|\|G|^[\^P]P|P\^|G.$$...\^.P|^!|G]$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[PG] ^(..[^^].{4,22}$|[^?]+\w)$|2
^(..[^^].{4,22}$|[^?]+\w)|~ ^..(.[!()3G^w]|.{7}|)|G\\ [[?C(].[-!)|w]|^P|^[^C|\\]*  • Correctness verified. Nov 21, 2014 at 7:27 # 37. Perl flavour - 30 \?[^w]*$$|[]C^]\w$|w.]|\w.\)


!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$^..(.[!G)(3w^]|.{7}$|$)|$\? \.\)|P[.?]|w\^|^[^|C\\]*|^P ^..(.[!)3G^w]|)|\^.{7}|G\) \?[^w]*$$|[]^C]\w+$|w\^|\|..\)  ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P
([^\\}<]{3}|][^]]|^).?[$PG]$
^(..[^^].{4,22}$|[^?]+\w)|2 ^(..[^^].{4,22}$|[^?]+\w)$|~ ^..(.[!()3G^w]|.{7}$|$)|G\\ [[?C(].[-!)|w]|^P|^[^C|\\]*$
[?[CP(].[-<)|w]|^P|^[^C|\\]*$^..(.{7}$|.[3Gw!^)]|$)|G.?.?\) ^...[3w!G)]|^[^\\C|]*$|G.?.?\)
^[^C\\|]+$|G.\)|\.\)|w\^|^P|\...?] ^P|!.3|w\^|^[^C\\|]+$|\.[)$-](?!.!) \?[^$w]*$|[]C^]\w|w.]|\w.\)  • Correctness verified. Nov 25, 2014 at 10:05 • Ahaha I'm pretty annoyed I didn't get this after coming so far with the first half :P Nov 25, 2014 at 10:11 ## 40. PCRE — 33 bytes []^C]\w|\w.\)|w[[+^]|\?[^w]*$$ Tested on Regex101 The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG]$
(?<!\\..)(?!]).$^[\w^]*$|!|]P|G]$!|[^?]P(CG|G..)? [^])]$|^\^?P|P.\].$([.$?]|G\])$|^\^?P|\]P ([P.?]$|[]^]P|G\]$|CG) !|((G.|P|\.)$|[^?]P|CG)$^[(!P]|G..$|]..\||[^?]P$^.{3,23}[.-~]..$|[^P?][PG] ^..(.[!G)(3w^]|.{7}|)|$\? \.\)|P[.$?]|w\^|^[^|C\\]*$|^P ^..(.[!)3G^w]|$)|\^.{7}$|G\) \?[^w$]*$|[]^C]\w+|w\^|\|..\) \w.\)|\?[^-]*$$|[]^C]\w$|w[+^]


And fail on these strings:

[PPCG]
^[P\^]
[^\]]$^\^?P [^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$^(.{,4}|.{9}|.{16,19}|.{5}P)$
^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[$PG]$^(..[^^].{4,22}$|[^?]+\w)|2 ^(..[^^].{4,22}$|[^?]+\w)$|~
^..(.[!()3G^w]|.{7}$|$)|G\\
[[?C(].[-!)|w]|^P|^[^C|\\]*$[?[CP(].[-<)|w]|^P|^[^C|\\]*$
^..(.{7}$|.[3Gw!^)]|$)|G.?.?\)
^...[3w!G)]|^[^\\C|]*$|G.?.?\) ^[^C\\|]+$|G.\)|\.\)|w\^|^P|\...?]
^P|!.3|w\^|^[^C\\|]+$|\.[)$-](?!.!)
\?[^$w]*$|[]C^]\w|w.]|\w.\)$..\\|\?[^w$]*$|w\^|[]^C]\w []^C]\w|\w.\)|w[[+^]|\?[^w]*$$ • Correctness verified. – Vi. Nov 25, 2014 at 21:14 • I have a 35 but I'm not satisfied with it so I'm going to see if I can get something more interesting Nov 27, 2014 at 3:39 • And I have 3 options for a 32-character answer, but the whole challenge got a bit boring (especially bookkeeping of Regex101 submissions and lists of fail/pass strings). If somebody wants, I can post an answer. – Vi. Nov 27, 2014 at 14:47 # 4. ECMAScript flavour - 5 bytes ^\^?P  ### The next answer has to match the following strings: PPCG ^P  ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P

• Correctness verified. Nov 13, 2014 at 19:34

# 5. ECMAScript flavour - 6 bytes

^[P^]P


Tested on Regex101.

Time to spice things up a bit with the success set.

### The next answer has to match the following strings:

PPCG
^P
^[P^]P


### And fail on these strings:

[PPCG]
^[P\^]
[^\]]$^\^?P  • Correctness verified. Nov 13, 2014 at 19:57 # 6. ECMAScript flavour - 9 bytes [^?][PG]$


Tested on Regex101.

### The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P

• Correctness verified. Nov 13, 2014 at 19:58

# 14. PCRE flavour - 25

!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
!|[^?]P(CG|G..)?$[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$([P.$?]$|[]^]P|G\]$|CG)$!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$ ### And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P
([^\\}<]{3}|][^]]|^).?[$PG]$
^(..[^^].{4,22}$|[^?]+\w)|2 ^(..[^^].{4,22}$|[^?]+\w)$|~  • Correctness verified. Nov 14, 2014 at 15:17 ## 35. PCRE — 35 bytes ^P|!.3|w\^|^[^C\\|]+$|\.[)$-](?!.!)  Tested on Regex101 The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG]$
(?<!\\..)(?!]).$^[\w^]*$|!|]P|G]$!|[^?]P(CG|G..)? [^])]$|^\^?P|P.\].$([.$?]|G\])$|^\^?P|\]P ([P.?]$|[]^]P|G\]$|CG) !|((G.|P|\.)$|[^?]P|CG)$^[(!P]|G..$|]..\||[^?]P$^.{3,23}[.-~]..$|[^P?][PG] ^..(.[!G)(3w^]|.{7}|)|$\? \.\)|P[.$?]|w\^|^[^|C\\]*$|^P ^..(.[!)3G^w]|$)|\^.{7}$|G\)  And fail on these strings: [PPCG] ^[P\^] [^\]]$
^\^?P
[^?][PG]$|<|PG ^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$
\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P
([^\\}<]{3}|][^]]|^).?[$PG]$
^(..[^^].{4,22}$|[^?]+\w)|2 ^(..[^^].{4,22}$|[^?]+\w)$|~ ^..(.[!()3G^w]|.{7}$|$)|G\\ [[?C(].[-!)|w]|^P|^[^C|\\]*$
[?[CP(].[-<)|w]|^P|^[^C|\\]*$^..(.{7}$|.[3Gw!^)]|$)|G.?.?\) ^...[3w!G)]|^[^\\C|]*$|G.?.?\)
^[^C\\|]+$|G.\)|\.\)|w\^|^P|\...?] ^P|!.3|w\^|^[^C\\|]+$|\.[)$-](?!.!)  • My verifier shows no errors. – Vi. Nov 25, 2014 at 0:58 • Correctness verified. (@Vi., the dashboard looks for this specific phrase.) Nov 25, 2014 at 0:59 • I though about using that phrase, but was not sure if I want to make my comment authoritative. – Vi. Nov 25, 2014 at 1:00 • My other 34-character answer mentioned before seems to work here. Waiting for 4 hours (or like that)... – Vi. Nov 25, 2014 at 1:03 • I don't bother hacking up - I delegate it to the computer. Maybe write an answer-posting bot using StackExchange API?.. – Vi. Nov 25, 2014 at 1:06 # 36. Python flavour - 32 \?[^w$]*$|[]^C]\w+|w\^|\|..\)  Tested on Regex101 I had three 32-byte regexes ready, and luckily one of them still works :D ### The next answer has to match the following strings: PPCG ^P ^[P^]P [^?][PG] (?<!\\..)(?!]). ^[\w^]*|!|]P|G]$$!|[^?]P(CG|G..)?$
[^])]$|^\^?P|P.\]. ([.?]|G\])$$|^\^?P|\]P$
([P.$?]$|[]^]P|G\]$|CG)$
!|((G.|P|\.)$|[^?]P|CG) ^[(!P]|G..|]..\||[^?]P ^.{3,23}[.-~]..$$|[^P?][PG]$
^..(.[!G)(3w^]|.{7}$|$)|$\? \.\)|P[.?]|w\^|^[^|C\\]*|^P ^..(.[!)3G^w]|)|\^.{7}|G\) \?[^w]*$$|[]^C]\w+$|w\^|\|..\)


### And fail on these strings:

[PPCG]
^[P\^]
[^\]]$^\^?P [^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$^(.{,4}|.{9}|.{16,19}|.{5}P)$
^[^?]*[PG]$|[?$].*$^[^[]P|]P|(G]|[.])$$\..$|!|\|G|^[\^P]P|P\^|G.$...\^.P|^!|G]$$|w|<!|^\^?P ([^\\}<]{3}|][^]]|^).?[$PG]$^(..[^^].{4,22}$|[^?]+\w)|2 ^(..[^^].{4,22}$|[^?]+\w)$|~
^..(.[!()3G^w]|.{7}$|$)|G\\
[[?C(].[-!)|w]|^P|^[^C|\\]*$[?[CP(].[-<)|w]|^P|^[^C|\\]*$
^..(.{7}$|.[3Gw!^)]|$)|G.?.?\)
^...[3w!G)]|^[^\\C|]*$|G.?.?\) ^[^C\\|]+$|G.\)|\.\)|w\^|^P|\...?]
^P|!.3|w\^|^[^C\\|]+$|\.[)$-](?!.!)

• Correctness verified. Nov 25, 2014 at 1:27
• Correctness as a Perl regex is also verified.
– Vi.
Nov 25, 2014 at 1:28
• Let's hope the question be inactive until tomorrow, as I have a pending 30-character answer to post.
– Vi.
Nov 25, 2014 at 1:55