A Different Kind of Meta Regex Golf

42

5

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.

Answering

The key thing to understand about this challenge is that only one person can answer at a time and each answer depends on the one before it.

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.
  • Post your answer in the following format:

    # N. [regex flavour] - [regex size in bytes]
    
        [regex]
    
    [link to online regex tester]
    
    [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.)

  • Another user should now review your submission and leave a comment "Correctness verified" if your answer follows all the rules (see below). If it doesn't, they should leave a comment pointing out any flaws. You've then got 15 minutes to fix those issues. If you don't, your answer will be deemed invalid, should be deleted, and someone else may post a follow-up answer to the previous one. (If this happens, you're free to submit a new answer any time.)

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.

function answersUrl(e){return"http://api.stackexchange.com/2.2/questions/"+QUESTION_ID+"/answers?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+ANSWER_FILTER}function commentsUrl(e,t){return"http://api.stackexchange.com/2.2/answers/"+e+"/comments?page="+t+"&pagesize=100&order=asc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){$.ajax({url:answersUrl(page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(e){answers.push.apply(answers,e.items);if(e.has_more)getAnswers();else{page=1;getFinalComments()}}})}function getFinalComments(){answers=answers.filter(shouldHaveHeading);answers=answers.filter(shouldHaveScore);$.ajax({url:commentsUrl(answers[0].answer_id,page++),method:"get",dataType:"jsonp",crossDomain:true,success:function(e){comments.push.apply(comments,e.items);if(e.has_more)getAnswers();else process()}})}function shouldHaveHeading(e){var t=false;try{t|=/^(#|&lt;h).*/.test(e.body_markdown);t|=["-","="].indexOf(e.body_markdown.split("\n")[1][0])>-1}catch(n){}return t}function shouldHaveScore(e){var t=false;try{t|=SIZE_REG.test(e.body_markdown.split("\n")[0])}catch(n){}return t}function findDuplicates(e){var t=false;var n={};e.forEach(function(e){var r=e.body_markdown.split("\n")[0].match(NUMBER_REG)[0];if(n[r])t=t||r;n[r]=true});return t}function hasBeenVerified(e,t){var n=false;t.forEach(function(t){n|=/correctness verified/i.test(t.body_markdown)&&e!=t.owner.user_id});return n}function userTimedOut(e){return NOW-e.creation_date*1e3<MSEC_PER_ANSWER}function getAuthorName(e){return e.owner.display_name}function getAnswerScore(e,t){e=parseInt(e);t=parseInt(t);return Math.pow(t/(30+e/5),e)}function process(){$("#last-user").append(answers[0].owner.display_name);var e=answers.slice(1).filter(userTimedOut).map(getAuthorName).join(", ");if(e)$("#timed-out-users").append(e);else $("#timed-out-notice").hide();var t=answers[0].body_markdown.split("\n")[0].match(NUMBER_REG)[0];var n=findDuplicates(answers);if(n){var r=$("#status-conflict-template").html();$("#challenge-status").append(r.replace("{{NUMBER}}",n));$("#challenge-status").addClass("conflict")}else if(!hasBeenVerified(answers[0].owner.user_id,comments)){var r=$("#status-verification-template").html();$("#challenge-status").append(r.replace("{{NUMBER}}",t));$("#challenge-status").addClass("verification")}else{var r=$("#status-next-template").html();$("#challenge-status").append(r.replace("{{NUMBER}}",t).replace("{{NEXT}}",parseInt(t)+1).replace("{{SIZE}}",29+Math.ceil((parseInt(t)+1)/5)));$("#challenge-status").addClass("next")}var i={};var s={};answers.forEach(function(e){var t=e.body_markdown.split("\n")[0];var n=$("#answer-template").html();var r=t.match(NUMBER_REG)[0];var o=(t.match(SIZE_REG)||[0])[0];var u=getAnswerScore(r,o);var a=getAuthorName(e);n=n.replace("{{NAME}}",a).replace("{{NUMBER}}",r).replace("{{SIZE}}",o).replace("{{SCORE}}",u.toExponential(5)).replace("{{LINK}}",e.share_link);n=$(n);$("#answers").append(n);i[a]=(i[a]||1)*u;s[a]=(s[a]||0)+1});var o=[];for(var u in i)if(i.hasOwnProperty(u)){o.push({name:u,numAnswers:s[u],score:i[u]})}o.sort(function(e,t){return e.score-t.score});var a=1;o.forEach(function(e){var t=$("#user-template").html();t=t.replace("{{NAME}}",e.name).replace("{{NUMBER}}",a++).replace("{{COUNT}}",e.numAnswers).replace("{{SCORE}}",e.score.toExponential(5));t=$(t);$("#users").append(t)})}var QUESTION_ID=41462;var ANSWER_FILTER="!*cCFgu5yS6BFQP8Z)xIZ.qGoikO4jB.Ahv_g-";var COMMENT_FILTER="!)Q2B_A497Z2O1kEH(Of5MUPK";var HOURS_PER_ANSWER=4;var MSEC_PER_ANSWER=HOURS_PER_ANSWER*60*60*1e3;var NOW=Date.now();var answers=[],comments=[],page=1;getAnswers();var SIZE_REG=/\d+(?=[^\d&]*(?:&lt;(?:s&gt;[^&]*&lt;\/s&gt;|[^&]+&gt;)[^\d&]*)*$)/;var NUMBER_REG=/\d+/
body{text-align:left!important}#challenge-status{font-weight:700;padding:10px;width:620px}#blocked-users{padding:10px;width:620px}.conflict{background:#994343;color:#fff}.verification{background:#FFDB12}.next{background:#75FF6E}#last-user,#timed-out-users{font-weight:700}#answer-list{padding:10px;width:300px;float:left}#leaderboard{padding:10px;width:290px;float:left}table thead{font-weight:700}table td{padding:5px}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <link rel="stylesheet" type="text/css" href="//cdn.sstatic.net/codegolf/all.css?v=83c949450c8b"> <div id="challenge-status"> </div><div id="blocked-users"> User <span id="last-user"></span> has posted the last answer, and may not post the next one. <div id="timed-out-notice"><span id="timed-out-users"></span> have answered within the last four hours and may not answer again yet. (If a user appears in this list twice, they must have answered twice within four hours!)</div></div><div id="answer-list"> <h2>List of Answers (newest first)</h2> <table class="answer-list"> <thead> <tr><td>No.</td><td>Author</td><td>Size</td><td>Score</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="leaderboard"> <h2>Leaderboard</h2> <table class="leaderboard"> <thead> <tr><td>No.</td><td>User</td><td>Answers</td><td>Score</td></tr></thead> <tbody id="users"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{NUMBER}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td>{{SCORE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="user-template"> <tr><td>{{NUMBER}}</td><td>{{NAME}}</td><td>{{COUNT}}</td><td>{{SCORE}}</td></tr></tbody> </table> <div id="status-conflict-template" style="display: none"> There is more than one answer with number {{NUMBER}}!<br>Please resolve this conflict before posting any further answer. </div><div id="status-verification-template" style="display: none"> Answer {{NUMBER}} has not been verified!<br>Please review the answer and post a comment reading "Correctness verified." on the answer if it is valid. Note that this has to be done by a different user than the author of the answer! </div><div id="status-next-template" style="display: none"> Answer {{NUMBER}} has been verified!<br>You may now post answer {{NEXT}}, using up to {{SIZE}} bytes. </div>

Martin Ender

Posted 2014-11-13T18:59:06.573

Reputation: 184 808

The rules turned out to be a bit stricter than I intended. After some discussion in chat I'm considering to relax the rules a little after the bounty has run out. I'll post 3 comments for the options I can think of below. Please indicate your preference by voting on the comments. – Martin Ender – 2014-11-22T12:36:15.607

2Rules are rules. Don't change them. It might be a shame that it's pretty much impossible to post another answer, but that doesn't justify changing the rules. – Martin Ender – 2014-11-22T12:37:22.820

2Allow for an additional byte every 10 answers. Correspondingly, change the answer score to (M/(30+N/10))^N. This would be applied retroactively, so the next answer could use up to 32 bytes. The change in scoring would not affect the top two places on the leaderboard, but the other users would be shuffled somewhat. – Martin Ender – 2014-11-22T12:38:31.200

8Allow for an additional byte every 5 answers. Correspondingly, change the answer score to (M/(30+N/5))^N. This would be applied retroactively, so the next answer could use up to 35 bytes. The change in scoring would not affect the top two places on the leaderboard, but the other users would be shuffled somewhat. – Martin Ender – 2014-11-22T12:39:33.537

(Note that the order of the leaderboard changes, because the alternative scoring methods would give a bigger advantage to late answers, with the 5-answer option emphasising late answers even more than the 10-answer option. This is probably a good thing, because I've received several complaints that the easy, early answers had too much of an advantage over late answers in the original rules.) – Martin Ender – 2014-11-22T13:08:43.773

4You people are strange and twisted. Why would you do this to yourselves? (It's fun to read though :P) – Joe – 2014-11-25T12:06:56.930

Answers

5

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$]*\$$
\?[^w$]*\$$|^P|\w.\)|w.?\+|w\^|[^?P]P$

Sp3000

Posted 2014-11-13T18:59:06.573

Reputation: 58 729

Correctness verified. – Martin Ender – 2014-11-29T18:30:49.137

My program struggles to find an answer less than 45 characters long... – Vi. – 2014-12-02T07:20:14.210

@Vi. Well I can say that a 38 solution does exist at least, but of course it'd be interesting if someone manages to get lower :) – Sp3000 – 2014-12-02T07:54:30.033

11

28. Python flavour - 29

\.\)|P[.$?]|w\^|^[^|C\\]*$|^P

Tested on Regex101

Lots of fiddling around was done - #4 in the pass set's probably the biggest pain, as it's a substring of a regex in the fail set, and also shares a suffix with another regex in the fail set.

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

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\\

Sp3000

Posted 2014-11-13T18:59:06.573

Reputation: 58 729

Correctness verified. – Martin Ender – 2014-11-15T12:52:05.497

9

24 - Python flavour - 29

^(..[^^].{4,22}\$|[^?]+\w)$|2

Tested here

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]$
^(..[^^].{4,22}\$|[^?]+\w)$|2

plannapus

Posted 2014-11-13T18:59:06.573

Reputation: 8 610

1Correctness verified. – feersum – 2014-11-14T13:22:43.233

8

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

n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

Posted 2014-11-13T18:59:06.573

Reputation: 5 683

Correctness verified. – FryAmTheEggman – 2014-11-13T21:00:34.737

Fixed the demo link. – Martin Ender – 2014-11-13T23:57:04.627

@FryAmTheEggman The script does read the comments, but only looks for "correctness verified" as a substring (ignoring case). – Martin Ender – 2014-11-14T00:20:21.823

@MartinBüttner Thanks, good to know. – FryAmTheEggman – 2014-11-14T00:30:00.960

3+1 for singlehandedly making this challenge 10 times harder – Sp3000 – 2014-11-15T13:14:52.653

8

10. Python flavor - 19

^[\w^]*$|!|]P|G]\$$

Tested on Regex101.

The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$
(?<!\\..)(?!]).$
^[\w^]*$|!|]P|G]\$$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)*[^\\|]*[^\]]$

feersum

Posted 2014-11-13T18:59:06.573

Reputation: 29 566

Correctness verified. – FryAmTheEggman – 2014-11-13T22:00:29.077

7

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\^]

Beta Decay

Posted 2014-11-13T18:59:06.573

Reputation: 21 478

1Correctness verified. – Martin Ender – 2014-11-13T19:19:00.380

7

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
^[^\\|]*(\\\\)*[^\\|]*[^\]]$

ndc5057

Posted 2014-11-13T18:59:06.573

Reputation: 201

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. – feersum – 2014-11-13T21:34:39.263

Whoops.... Should have been a * instead of +. I edited my answer – ndc5057 – 2014-11-13T21:36:30.787

Correctness verfied. – FryAmTheEggman – 2014-11-13T21:37:46.367

7

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]$
(?<!\\..)(?!]).$
^[\w^]*$|!|]P|G]\$$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$

user2428118

Posted 2014-11-13T18:59:06.573

Reputation: 2 000

Correctness verified. – feersum – 2014-11-13T22:55:50.483

7

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]$

jimmy23013

Posted 2014-11-13T18:59:06.573

Reputation: 34 042

What does [^] do? – feersum – 2014-11-14T12:34:25.843

@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. – Martin Ender – 2014-11-14T12:37:13.390

Correctness verified. – Martin Ender – 2014-11-14T12:37:54.953

7

29. PCRE flavour - 28

^..(.[!)3G^w]|$)|\^.{7}$|G\)

Tested on Regex101

This answer still works...

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\\

jimmy23013

Posted 2014-11-13T18:59:06.573

Reputation: 34 042

Correctness verified. – Martin Ender – 2014-11-20T15:03:50.447

1Nice! Barring reshuffling, that's exactly what I had – Sp3000 – 2014-11-20T19:18:42.993

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. – 2014-11-21T04:06:15.703

@Vi A genetic algorithm eh, interesting ideas you have there :P – Sp3000 – 2014-11-21T05:33:03.253

@Sp3000, Now 30 characters... But another anwser has arrived, so need to restart. – Vi. – 2014-11-21T09:55:19.153

6

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|\\]*$

Vi.

Posted 2014-11-13T18:59:06.573

Reputation: 2 644

Correctness verified. – Martin Ender – 2014-11-24T11:35:34.283

Ahaha nice - did you use the previous answers as seeds for the population or did it just end up looking like the previous one? – Sp3000 – 2014-11-24T12:00:06.987

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. – 2014-11-24T12:06:49.257

(Meanwhile, 31-character candidate for next answer is already found) – Vi. – 2014-11-24T12:09:06.877

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. – 2014-11-24T13:01:53.497

If it stayed at 29, your regex would probably have been last ;) (I do have a 30 though) – Sp3000 – 2014-11-24T13:22:38.580

My program have also already printed the 30-character one. Let's consider "The last not-more-than-29 answer" a side challenge. – Vi. – 2014-11-24T13:26:41.670

6

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.?.?\)

hwnd

Posted 2014-11-13T18:59:06.573

Reputation: 433

1Correctness verified. – Martin Ender – 2014-11-24T13:40:56.580

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. – 2014-11-24T14:03:38.480

3@Vi. I guess hwnd's feeling nice today – Sp3000 – 2014-11-24T14:04:43.090

I'll make it harder as it keeps going. – hwnd – 2014-11-24T14:06:51.530

5

1. ECMAScript flavour - 2 bytes

^P

Test it on Regex101.

The initial matching set is PPCG and the failing set [PPCG]. Therefore, this regex simply tests that the string starts with P.

The next answer has to match the following strings:

PPCG
^P

And fail on these strings:

[PPCG]

Martin Ender

Posted 2014-11-13T18:59:06.573

Reputation: 184 808

3Correctness verified. – Beta Decay – 2014-11-13T19:09:16.543

5

3. ECMAScript flavour - 6 bytes

[^\]]$

Test it here

The next answer has to match the following strings:

PPCG
^P

And fail on the these strings:

[PPCG]
^[P\^]
[^\]]$

hmatt1

Posted 2014-11-13T18:59:06.573

Reputation: 3 356

1Correctness verified. – Beta Decay – 2014-11-13T19:27:08.503

5

7. Python flavour - 16

(?<!\\..)(?!]).$

Tested on Regex101

Gotta add a \ to the match list :)

The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$
(?<!\\..)(?!]).$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P

FryAmTheEggman

Posted 2014-11-13T18:59:06.573

Reputation: 16 206

Correctness verified. – NinjaBearMonkey – 2014-11-13T20:46:13.183

This…this is devious. – wchargin – 2014-11-14T06:05:39.560

@WChargin Thanks :) You should check out some of user23013 or n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ answers; some are quite 'devious' ;) – FryAmTheEggman – 2014-11-14T13:43:51.670

5

12. ECMAScript flavor - 17

!|[^?]P(CG|G..)?$

Test it here.

The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$
(?<!\\..)(?!]).$
^[\w^]*$|!|]P|G]\$$
!|[^?]P(CG|G..)?$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$

NinjaBearMonkey

Posted 2014-11-13T18:59:06.573

Reputation: 9 925

Correctness verified. – Martin Ender – 2014-11-13T23:54:39.323

5

22. PCRE Flavor – 29 bytes

Since the original #22 is not modified for 1 hour I assume it has become invalid.

^.{3,23}[.-~]..\$$|[^P?][PG]$

Demo

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

kennytm

Posted 2014-11-13T18:59:06.573

Reputation: 6 847

1Correctness verified. (And yes, that's right, the previous 22 is now invalid.) – Martin Ender – 2014-11-14T11:00:56.093

5

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]$
^..(.[!G)(3w^]|.{7}$|$)|\$\?

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)$|~

feersum

Posted 2014-11-13T18:59:06.573

Reputation: 29 566

Correctness verified. – Martin Ender – 2014-11-14T15:21:57.923

5

30. Python flavour - 28

[[?C(].[-!)|w]|^P|^[^C|\\]*$

Tested on Regex101

When there's a will...

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|\\]*$

Sp3000

Posted 2014-11-13T18:59:06.573

Reputation: 58 729

Correctness verified. – jimmy23013 – 2014-11-21T07:27:44.517

5

37. Perl flavour - 30

\?[^$w]*\$$|[]C^]\w$|w.]|\w.\)

Submission on Regex101.

The solution was produced by the the same program as before. The program has also printed 29-character solution \?[^$w]*\$|[]^C]\w)$|w.]|\w.\, I don't know why, as it looks like a malformed regex...

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\\|]+$|\.[)$-](?!.!)
\?[^$w]*\$$|[]C^]\w$|w.]|\w.\)

Vi.

Posted 2014-11-13T18:59:06.573

Reputation: 2 644

Correctness verified. – Martin Ender – 2014-11-25T10:05:20.197

Ahaha I'm pretty annoyed I didn't get this after coming so far with the first half :P – Sp3000 – 2014-11-25T10:11:58.737

5

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$]*\$$

hwnd

Posted 2014-11-13T18:59:06.573

Reputation: 433

Correctness verified. – Vi. – 2014-11-25T21:14:12.240

1I have a 35 but I'm not satisfied with it so I'm going to see if I can get something more interesting – Sp3000 – 2014-11-27T03:39:21.320

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. – 2014-11-27T14:47:00.180

4

4. ECMAScript flavour - 5 bytes

^\^?P

Test it here.

The next answer has to match the following strings:

PPCG
^P

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P

jimmy23013

Posted 2014-11-13T18:59:06.573

Reputation: 34 042

1Correctness verified. – Beta Decay – 2014-11-13T19:34:38.857

4

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

FireFly

Posted 2014-11-13T18:59:06.573

Reputation: 7 107

Correctness verified. – FryAmTheEggman – 2014-11-13T19:57:02.633

4

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

Ypnypn

Posted 2014-11-13T18:59:06.573

Reputation: 10 485

1Correctness verified. – FireFly – 2014-11-13T19:58:55.100

4

14. PCRE flavour - 25

([.$?]|G\])\$$|^\^?P|\]P$

Tested on Regex101

This is starting to get quite hard.

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$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$

FireFly

Posted 2014-11-13T18:59:06.573

Reputation: 7 107

Correctness verified. – Martin Ender – 2014-11-14T00:23:50.000

4

15. PCRE flavour - 26

([P.$?]\$|[]^]P|G\]\$|CG)$

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)$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$

hmatt1

Posted 2014-11-13T18:59:06.573

Reputation: 3 356

1Correctness verified. – FireFly – 2014-11-14T00:44:28.903

4

16. PCRE flavor - 21

^[^?]*[PG]$|[?$].*\$$

Tested on Regex 101.

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)$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$
^[^?]*[PG]$|[?$].*\$$

es1024

Posted 2014-11-13T18:59:06.573

Reputation: 8 953

It doesn't match PPCG. – jimmy23013 – 2014-11-14T00:55:58.567

@user23013 fixed – es1024 – 2014-11-14T01:07:38.637

Correctness verified. – jimmy23013 – 2014-11-14T01:41:56.380

4

25. PCRE flavour - 29

^(..[^^].{4,22}\$|[^?]+\w)$|~

Tested here. (The test regex contains an additional \n to make sure that no match spans multiple lines. This is not necessary to match each individual string.)

That was a low-hanging fruit! :) I have to congratulate plannapus though, this regex is amazingly elegant for the current test sets. If you want to upvote this answer, make sure to upvote the previous one, too!

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]$
^(..[^^].{4,22}\$|[^?]+\w)$|2
^(..[^^].{4,22}\$|[^?]+\w)$|~

Martin Ender

Posted 2014-11-13T18:59:06.573

Reputation: 184 808

1Correctness verified. – feersum – 2014-11-14T15:17:47.130

4

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\\|]+$|\.[)$-](?!.!)

hwnd

Posted 2014-11-13T18:59:06.573

Reputation: 433

My verifier shows no errors. – Vi. – 2014-11-25T00:58:26.120

Correctness verified. (@Vi., the dashboard looks for this specific phrase.) – Martin Ender – 2014-11-25T00:59:03.933

I though about using that phrase, but was not sure if I want to make my comment authoritative. – Vi. – 2014-11-25T01:00:34.253

My other 34-character answer mentioned before seems to work here. Waiting for 4 hours (or like that)... – Vi. – 2014-11-25T01:03:29.310

I don't bother hacking up - I delegate it to the computer. Maybe write an answer-posting bot using StackExchange API?.. – Vi. – 2014-11-25T01:06:52.503

4

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\\|]+$|\.[)$-](?!.!)

Sp3000

Posted 2014-11-13T18:59:06.573

Reputation: 58 729

1Correctness verified. – Martin Ender – 2014-11-25T01:27:50.977

Correctness as a Perl regex is also verified. – Vi. – 2014-11-25T01:28:08.820

Let's hope the question be inactive until tomorrow, as I have a pending 30-character answer to post. – Vi. – 2014-11-25T01:55:52.110

4

38. Python flavour - 31

\$..\\|\?[^w$]*\$$|w\^|[]^C]\w$

Tested on Regex101

I'm feeling pretty silly now, because Vi. golfed out a useless + from my last answer.

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\\|]+$|\.[)$-](?!.!)
\?[^$w]*\$$|[]C^]\w$|w.]|\w.\)
\$..\\|\?[^w$]*\$$|w\^|[]^C]\w$

Sp3000

Posted 2014-11-13T18:59:06.573

Reputation: 58 729

1Correctness verified. – Martin Ender – 2014-11-25T10:58:29.627

My solver immediately found a 32-character solution - a variation on the same theme. – Vi. – 2014-11-25T11:23:15.500

@Vi. I'm expecting this to continue until someone breaks \?[^w$]*\$$ – Sp3000 – 2014-11-25T11:23:47.670

So, nobody else want to post an answer? – Vi. – 2014-11-25T17:12:06.703

Feel free, I'm observing. – hwnd – 2014-11-25T17:30:41.610

4

39. Perl flavour - 32

\w.\)|\?[^-$]*\$$|[]^C]\w$|w[+^]

Regex101 submission

Generated by the program. There are also 2 competing 32-character solutions.

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$

Vi.

Posted 2014-11-13T18:59:06.573

Reputation: 2 644

Correctness verified. – Martin Ender – 2014-11-25T18:05:04.753

4

41. PCRE - 36

[]^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[+^]
[]^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$]*\$$

Paul Guyot

Posted 2014-11-13T18:59:06.573

Reputation: 221

1Correctness verified. – Martin Ender – 2014-11-27T14:01:51.737

3

13. PCRE flavor - 20

[^])]\$|^\^?P|P.\].$

Test it here.

The next answer has to match the following strings:

PPCG
^P
^[P^]P
[^?][PG]$
(?<!\\..)(?!]).$
^[\w^]*$|!|]P|G]\$$
!|[^?]P(CG|G..)?$
[^])]\$|^\^?P|P.\].$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$

jimmy23013

Posted 2014-11-13T18:59:06.573

Reputation: 34 042

The previous answer (mine) has not been verified yet, so I hope it's valid so you don't lose your work. – NinjaBearMonkey – 2014-11-13T23:52:04.987

@hsl taken care of that. user23013, please watch out for that next time ;) – Martin Ender – 2014-11-13T23:54:59.893

Correctness verified. – Martin Ender – 2014-11-13T23:55:48.467

3

17. Python flavor - 21

^[^[]P|]P|(G]|[.])\$$

Tested on Regex 101.

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)$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$
^[^?]*[PG]$|[?$].*\$$
^[^[]P|]P|(G]|[.])\$$

ndc5057

Posted 2014-11-13T18:59:06.573

Reputation: 201

Correctness verified. – FryAmTheEggman – 2014-11-14T01:59:51.650

3

18. PCRE Flavor - 25 bytes

!|((G.|P|\.)\$|[^?]P|CG)$

Tested on Regex 101.

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)$

And fail on these strings:

[PPCG]
^[P\^]
[^\]]$
^\^?P
[^?][PG]$|<|PG
^[^\\|]*(\\\\)+[^\\|]*[^\]]$
^(.{,4}|.{9}|.{16,19}|.{5}P)$
^[^?]*[PG]$|[?$].*\$$
^[^[]P|]P|(G]|[.])\$$

hmatt1

Posted 2014-11-13T18:59:06.573

Reputation: 3 356

I got ninja'd :) – FryAmTheEggman – 2014-11-14T04:53:06.467

@FryAmTheEggman I'm sorry! Hopefully it isn't too different. – hmatt1 – 2014-11-14T04:53:56.543

Actually mine still works, just going to verify yours :) – FryAmTheEggman – 2014-11-14T04:54:39.793

Oh good! I figured putting my new regex in the match would make it easier on future ones. – hmatt1 – 2014-11-14T04:55:24.200

1Correctness verified. – FryAmTheEggman – 2014-11-14T04:55:46.827

3

19. Python flavour - 28

\..$|!|\|G|^[\^P]P|P\^|G.\$$

Tested on Regex101.

I tried so many different ways. All 28 characters. :'(

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)$

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.\$$

FryAmTheEggman

Posted 2014-11-13T18:59:06.573

Reputation: 16 206

Correctness verified. – hmatt1 – 2014-11-14T04:57:53.253

3

20. PCRE flavour - 27

...\^.P|^!|G]\$$|w|<!|^\^?P

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)$

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

jimmy23013

Posted 2014-11-13T18:59:06.573

Reputation: 34 042

Correctness verified. – es1024 – 2014-11-14T07:04:38.167

3

21. ECMAScript flavour - 24 bytes

... The moment when you see one accept string is the prefix of a reject string, and realize that the longer one is from your earlier answer.

^[(!P]|G..$|]..\||[^?]P$

Demo

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$

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

n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳

Posted 2014-11-13T18:59:06.573

Reputation: 5 683

Please also check the input/output if I messed up my copy/paste. – n̴̖̋h̷͉̃a̷̭̿h̸̡̅ẗ̵̨́d̷̰̀ĥ̷̳ – 2014-11-14T06:21:28.850

Correctness verified. – es1024 – 2014-11-14T07:05:16.263

3

27. PCRE Flavor - 27

^..(.[!()3G^w]|.{7}$|$)|G\\

Demo. The previous answer clearly works, so... thanks? :)

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}$|$)|\$\?

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\\

kennytm

Posted 2014-11-13T18:59:06.573

Reputation: 6 847

Correctness verified. – Martin Ender – 2014-11-14T20:54:36.177

3

33. Python flavour - 30

^...[3w!G)]|^[^\\C|]*$|G.?.?\)

Tested on Regex101

Originally I had the 30 char [.!w].[]?3P]|^P|^[^C|\\]*$|\?< for the previous set, but I took too long trying to find a 29 and hwnd inadvertedly ruled out my submission.

So instead I mashed together two common themes we've had so far, just for fun :)

Note: Please remember that when testing ^[^C|\\]*$ or anything else that uses [^...], put a \n in the character set. Otherwise Regex101 may match over lines.

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.?.?\)

Sp3000

Posted 2014-11-13T18:59:06.573

Reputation: 58 729

Correctness verified. – Martin Ender – 2014-11-24T16:00:32.837

3

34. Perl flavour - 34

^[^C\\|]+$|G.\)|\.\)|w\^|^P|\...?]

Submission on Regex101 - there is additional \n added for Regex101 there, as previous answer suggested

The solution was produced by the the same program as before (with little tweaks). 35-character solutions were easy to find, but I waited for 34 version to make 34'th answer be 34 characters.

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|\...?]

Vi.

Posted 2014-11-13T18:59:06.573

Reputation: 2 644

There is also another 34 variant, substationally different with the posted one. – Vi. – 2014-11-25T00:28:43.337

Correctness verified. – Martin Ender – 2014-11-25T00:43:45.043