Objective Given an input of text that does not contain characters [ or ], perform the following actions:

  1. For every instance of Amen with at least one capital letter (so all instances of Amen excluding amen), output that same Amen (retain capitalization).
  2. For every instance of /all the people said[?: ]/i (that's a Regular Expression), also output Amen (any case is fine.)

After every output, you may choose any constant separator, e.g. a newline, space, or nothing.

This is a , so the shortest program in bytes wins.

Example IOs

Input: I said AMEN! AMEN, PEOPLE!
Output: AMENAMEN         ; any separator is fine, I choose none.

Input: amen amen amen amen
Output:                  ; nothing

Input:                   ; empty
Output:                  ; nothing

Input: *blah blah blah* And all the people said?
Output: Amen

Input: all the people said:
Output: Amen

Input: AMEN AMeN AmeN aMEN amen AmEn
Output: AMEN AMeN AmeN aMEN AmEn

Input: All the people said Amen! And all the people said AMEN!
Output: Amen Amen Amen AMEN

Input: LAMEN! Amen.
Output: AMEN Amen

Input: AmenAmenAmenAmenAMENamen
Output: Amen Amen Amen Amen AMEN

Input: And he was like, "Amen", then we were all like, "Amen, bruh."
Output: Amen Amen

Input: And all the aMen people said.
Output: aMen


  • -20 bytes if you can "grab" the punctuation that follows the Amen, i.e., Amen! => Amen!, AmEN. => AmEN., I said Amen, bruh. => Amen,, and AMEN!!!! => AMEN!!!!. ! is the only character to be preserved multiple times. .?!, are the only characters to be preserved thus.
  • -40 bytes if, there is an instance of amen, output, Heresy! at index [i] instead of nothing, where [i] is the index of the offending word i.e. amen.

Bonus IOs

Input and output is of the form input => output. (Separator here is a space.)

Can I get an Amen! => Amen!
AMEN! and AMEN! and a final Amen... => AMEN! AMEN! Amen.
Amen? Amen, and amEn! => Amen? Amen, amEn!

The man sighed and said, "amen," and left. It's AMEN! => Heresy! at index [26] AMEN!


Here is a Stack Snippet to generate both a regular leaderboard and an overview of winners by language.

To make sure that your answer shows up, please start your answer with a headline, using the following Markdown template:

# Language Name, N bytes

where N is the size of your submission. If you improve your score, you can keep old scores in the headline, by striking them through. For instance:

# Ruby, <s>104</s> <s>101</s> 96 bytes

If there you want to include multiple numbers in your header (e.g. because your score is the sum of two files or you want to list interpreter flag penalties separately), make sure that the actual score is the last number in the header:

# Perl, 43 + 2 (-p flag) = 45 bytes

You can also make the language name a link which will then show up in the leaderboard snippet:

# [><>](http://esolangs.org/wiki/Fish), 121 bytes

var QUESTION_ID=64109,OVERRIDE_USER=8478;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 commentUrl(e,s){return"http://api.stackexchange.com/2.2/answers/"+s.join(";")+"/comments?page="+e+"&pagesize=100&order=desc&sort=creation&site=codegolf&filter="+COMMENT_FILTER}function getAnswers(){jQuery.ajax({url:answersUrl(answer_page++),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){answers.push.apply(answers,e.items),answers_hash=[],answer_ids=[],e.items.forEach(function(e){e.comments=[];var s=+e.share_link.match(/\d+/);answer_ids.push(s),answers_hash[s]=e}),e.has_more||(more_answers=!1),comment_page=1,getComments()}})}function getComments(){jQuery.ajax({url:commentUrl(comment_page++,answer_ids),method:"get",dataType:"jsonp",crossDomain:!0,success:function(e){e.items.forEach(function(e){e.owner.user_id===OVERRIDE_USER&&answers_hash[e.post_id].comments.push(e)}),e.has_more?getComments():more_answers?getAnswers():process()}})}function getAuthorName(e){return e.owner.display_name}function process(){var e=[];answers.forEach(function(s){var r=s.body;s.comments.forEach(function(e){OVERRIDE_REG.test(e.body)&&(r="<h1>"+e.body.replace(OVERRIDE_REG,"")+"</h1>")});var a=r.match(SCORE_REG);a&&e.push({user:getAuthorName(s),size:+a[2],language:a[1],link:s.share_link})}),e.sort(function(e,s){var r=e.size,a=s.size;return r-a});var s={},r=1,a=null,n=1;e.forEach(function(e){e.size!=a&&(n=r),a=e.size,++r;var t=jQuery("#answer-template").html();t=t.replace("{{PLACE}}",n+".").replace("{{NAME}}",e.user).replace("{{LANGUAGE}}",e.language).replace("{{SIZE}}",e.size).replace("{{LINK}}",e.link),t=jQuery(t),jQuery("#answers").append(t);var o=e.language;/<a/.test(o)&&(o=jQuery(o).text()),s[o]=s[o]||{lang:e.language,user:e.user,size:e.size,link:e.link}});var t=[];for(var o in s)s.hasOwnProperty(o)&&t.push(s[o]);t.sort(function(e,s){return e.lang>s.lang?1:e.lang<s.lang?-1:0});for(var c=0;c<t.length;++c){var i=jQuery("#language-template").html(),o=t[c];i=i.replace("{{LANGUAGE}}",o.lang).replace("{{NAME}}",o.user).replace("{{SIZE}}",o.size).replace("{{LINK}}",o.link),i=jQuery(i),jQuery("#languages").append(i)}}var ANSWER_FILTER="!t)IWYnsLAZle2tQ3KqrVveCRJfxcRLe",COMMENT_FILTER="!)Q2B_A2kjfAiU78X(md6BoYk",answers=[],answers_hash,answer_ids,answer_page=1,more_answers=!0,comment_page;getAnswers();var SCORE_REG=/<h\d>\s*([^\n,]*[^\s,]),.*?([-\d.]+)(?=[^\n\d<>]*(?:<(?:s>[^\n<>]*<\/s>|[^\n<>]+>)[^\n\d<>]*)*<\/h\d>)/,OVERRIDE_REG=/^Override\s*header:\s*/i;
body{text-align:left!important}#answer-list,#language-list{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="answer-list"> <h2>Leaderboard</h2> <table class="answer-list"> <thead> <tr><td></td><td>Author</td><td>Language</td><td>Size</td></tr></thead> <tbody id="answers"> </tbody> </table> </div><div id="language-list"> <h2>Winners by Language</h2> <table class="language-list"> <thead> <tr><td>Language</td><td>User</td><td>Score</td></tr></thead> <tbody id="languages"> </tbody> </table> </div><table style="display: none"> <tbody id="answer-template"> <tr><td>{{PLACE}}</td><td>{{NAME}}</td><td>{{LANGUAGE}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table> <table style="display: none"> <tbody id="language-template"> <tr><td>{{LANGUAGE}}</td><td>{{NAME}}</td><td>{{SIZE}}</td><td><a href="{{LINK}}">Link</a></td></tr></tbody> </table>

  • \$\begingroup\$ Do the amens have to be in order? \$\endgroup\$
    – Zach Gates
    Commented Nov 17, 2015 at 14:29
  • \$\begingroup\$ @ZachGates Yes. \$\endgroup\$ Commented Nov 17, 2015 at 14:35
  • \$\begingroup\$ How do you determine the "index of the offending phrase"? \$\endgroup\$
    – Zach Gates
    Commented Nov 17, 2015 at 19:25
  • \$\begingroup\$ @ZachGates To be the index of the a in amen. E.g., G amen => 2, if your language is zero-indexed; 3 if it is one-indexed. \$\endgroup\$ Commented Nov 17, 2015 at 19:26
  • \$\begingroup\$ AMEN!!!! => AMEN!!!! and yet and a final Amen... => Amen.? \$\endgroup\$ Commented Nov 17, 2015 at 20:07

12 Answers 12


Retina, 37 bytes

i`all the people said[?: ]

The code if 57 bytes long and qualifies for the -20 bytes bonus. Try it online!

Thanks to @MartinBüttner for porting my Perl answer to Retina!

How it works

S`                          Split the input at...
  amen                      matches of "amen".
i`                          Case-insensitively search for
  all the people said[?: ]  matches of "all the people said",
                            followed by '?', ':' or ' '...
    amenx                   and replace them with "amenx"
!i`                         Print all case-insensitive matches of...
  amen([.,?]|!*)            "amen", followed either by a single '.',
                            ',' or '?', or by 0 or more '!'s.
  • 1
    \$\begingroup\$ May I use your ([.,?]|!*) punctuation match pattern for my answer? I saw it and couldn't unsee it (and I certainly couldn't find a better solution!). It's certainly not going to beat yours :), but I don't want to plagiarize, and I'm not totally sure of the etiquette for borrowing solutions to sub-problems like this. \$\endgroup\$
    – apsillers
    Commented Nov 18, 2015 at 16:23
  • 3
    \$\begingroup\$ @apsillers Legally, all content here is licensed as CC-BY-SA, meaning that you can use it freely with attribution. Morally, porting somebody's solution to another language to outgolf him is more or less frowned upon, but taking a tiny part of somebody's answer is always fine. \$\endgroup\$
    – Dennis
    Commented Nov 18, 2015 at 17:08

VBA, 193 bytes

Function v(b)
For i=1 To Len(b)
If StrConv(Mid(b,i,19),2) Like "all the people said" Then v=v& "Amen"
If StrConv(q,2) Like k And Not q Like k Then v=v& q
End Function

No Separation, No Regex, No Bonus. Had a version that got both Bonus but was MUCH longer.

  • \$\begingroup\$ You van lose 1 byte byte by changing for i=1 to to for i=1To \$\endgroup\$ Commented Mar 28, 2017 at 21:50

Perl, 51 bytes

s/amen/x/g;s/all the people said[?: ]/amenx/ig;say/amen[.,?]|amen!*/ig

The actual source code contains 70 bytes, it must be run with perl -nE (+1 byte), and it qualifies for the -20 bytes bonus.


Python 2, 155 bytes

from re import*
for i in split(m,input()):
 if F("((?i)all the people said[?: ])",i):print'AMen'
 elif F(m,i)and i!="amen":print i


$ python2 test.py
"All the people said Amen! And all the people said AMEN!"

JavaScript, 88 bytes

108 bytes - 20 bytes (catches punctuation)

alert(prompt().replace(/amen/g,' ').replace(/all the people said[?: ]/ig,'Amen').match(/amen(\??!?\.?)+/ig))
  • \$\begingroup\$ This prints Amen?!. for input Amen?!., and Amen! for input Amen!!!. \$\endgroup\$
    – Dennis
    Commented Nov 18, 2015 at 4:42
  • \$\begingroup\$ @Dennis Sorry, didn't think about multiple punctuation marks being used at once, I'll fix it. \$\endgroup\$
    – Oliver
    Commented Nov 18, 2015 at 4:45
  • \$\begingroup\$ @Dennis Just fixed it. \$\endgroup\$
    – Oliver
    Commented Nov 18, 2015 at 5:54
  • \$\begingroup\$ @apsillers Didn't notice that either. I'll try to fix it later. \$\endgroup\$
    – Oliver
    Commented Nov 18, 2015 at 21:21
  • \$\begingroup\$ @apsillers Fixed \$\endgroup\$
    – Oliver
    Commented Nov 18, 2015 at 21:25

grep and sed, 85 83 84 77 - 20 = 57 bytes

sed 's/all the people said[?: ]/Amenx/ig'|grep -oi 'amen[.,!?]*'|grep \[AMEN]
  • 1
    \$\begingroup\$ This will print Amen? for the input all the people said??. The best workaround I could find was to replace the string with Amenx. \$\endgroup\$
    – Dennis
    Commented Nov 18, 2015 at 4:48
  • \$\begingroup\$ Thanks @Dennis, I've used your workaround and updated the score. \$\endgroup\$
    – Thor
    Commented Nov 18, 2015 at 8:15
  • 1
    \$\begingroup\$ This will print amen. for the input amen.. Fixing this will shorten your answer: just change grep -v '^[amen]*$' to grep \[AMEN]. \$\endgroup\$
    – hvd
    Commented Nov 18, 2015 at 19:47
  • \$\begingroup\$ @hvd: You're right, this is much better :-) \$\endgroup\$
    – Thor
    Commented Nov 19, 2015 at 8:38

Perl, 103 - 60 = 43 bytes

#!perl -p
s/amen/Heresy! at index [@-]/g;s/all the people said[?: ]/Amen /gi;s/(amen([.,?]|!*)|h[^h]+\])\K|.//gi

Counting the shebang as one, input is taken from stdin. Maintains punctuation for -20 bytes, and identifies heresy for -40.

Sample Usage

$ echo amen amen, and all the people said?? amen amen | perl amen.pl
Heresy! at index [0]Heresy! at index [5]AmenHeresy! at index [37]Heresy! at index [42]

$ echo AMEN AMeN AmeN aMEN amen AmEn | perl amen.pl
AMENAMeNAmeNaMENHeresy! at index [20]AmEn

$ echo The man sighed and said, "amen," and left. It's AMEN! | perl amen.pl
Heresy! at index [26]AMEN!

Perl, 70 - 20 = 50 bytes

#!perl -p
s/all the people said[?: ]/Amen /gi;s/amen|(?i:amen([.,?]|!*))\K|.//g

Counting the shebang as one, input is taken from stdin. Maintains punctuation for -20 bytes.

Sample Usage

$ echo All the people said Amen, and all the people said AMEN!! | perl primo-amen.pl
  • \$\begingroup\$ Your first solution fails for input like ha]. (Nevermind, just saw the OP's comment that the input can't contain square brackets...this question has morphed so many times I can't keep track.) \$\endgroup\$ Commented Nov 18, 2015 at 18:10
  • \$\begingroup\$ @ThisSuitIsBlackNot I don't think the OP has answered that question. \$\endgroup\$
    – Dennis
    Commented Nov 18, 2015 at 19:31
  • \$\begingroup\$ @Dennis Ah, you're right. Yet another unknown. \$\endgroup\$ Commented Nov 18, 2015 at 19:37

𝔼𝕊𝕄𝕚𝕟, 66 - 20 = 46 chars / 80 - 20 = 60 bytes

ïċ/all the people said[?: ]⍀,`Amen”ċ(/amen⌿,`x”ĉ/amen(\??!?\.?)+⍀)

Try it here - Firefox only.

First time here at PPCGSE. Hope this golf is pretty good.

EDIT: Actually, I'm beating CJam (in char count), so that's pretty good!

  • 1
    \$\begingroup\$ Yay, someone's using my language! Not bad for your first post. \$\endgroup\$ Commented Nov 22, 2015 at 5:20

CJam, 57 bytes

 q_,,\f{\:I>_4<_el"amen":A=*_A="Heresy! at index ["I+']+@?oK<)"?: "&,*el"all the people said"=A*o}

The code is 97 bytes long and qualifies for the -40 bytes bonus.

Try it online in the CJam interpreter.

  • 1
    \$\begingroup\$ CJam is longer than Perl? o_O \$\endgroup\$ Commented Nov 17, 2015 at 16:41
  • \$\begingroup\$ CJam doesn't have regular expressions, so that's not at all surprising. \$\endgroup\$
    – Dennis
    Commented Nov 17, 2015 at 16:43
  • \$\begingroup\$ Ohhh... writes that down \$\endgroup\$ Commented Nov 17, 2015 at 16:44

JavaScript, 100 bytes

alert(prompt().replace(/all the people said[?: ]/ig,'Amen').replace(/amen/g,'x').match(/amen/ig));
  • 3
    \$\begingroup\$ You can use x=prompt(); and you can use also alert(prompt().replace(...).replace(...).match) \$\endgroup\$ Commented Nov 18, 2015 at 2:15
  • \$\begingroup\$ Done. Now it's 100 chars long. \$\endgroup\$
    – Nautilus
    Commented Nov 18, 2015 at 15:08

JavaScript, 136 135 - 40 - 20 = 75 bytes

alert(prompt(A="ameN").replace(/all the people said[?: ]|(amen)([.,?]|!*)|./ig,(v,a,p,i)=>a?a>A?`Heresy! at index [${i}]`:v:v[1]?A:""))


This code is driven by a three-part regex that feeds results into a replace callback. The parts are:

  • all the people said[?: ] - simply matches the required all the people said pattern
  • (amen)([.,?]|!*) - matches any-case amen and punctuation (one of .,? or zero or more !, which makes the punctuation optional) into separate match groups -- credit to Dennis for the punctuation pattern
  • . - matches any other character, not part of the above patterns, one at the time

Therefore, any match must either be an all-the-people string, an Amen match with optional punctuation, or a single character not part of either of those phrases. We use logic in the replacer callback to save and replace the appropriate parts of the string, and change every other character to the empty string.

  // store "ameN" in `A` and then prompt
      // three-part regex:
      /all the people said[?: ]|(amen)([.,?]|!*)|./ig,

      // replacer callback, with arguments
      //   v - total match
      //   a - "amen" match group
      //   p - punctuation match group (unused)
      //   i - index of match
        a?           // if there is an Amen match
          a>A?      //   if the Amen is lowercase (lexically more than "ameN")
               `Heresy! at index [${i}]`
              :v     //   otherwise, output full Amen with punctuation
         :v[1]?      // if there is no Amen, but more than one character
          A          //   this must be all-the-people; output "ameN"
         :""         // otherwise, not an Amen or all-the-people

Python 2, 191 - 40 = 151 bytes

for j in range(len(i)):
 if s[:-1].lower()=="all the people said"and s[-1]in'?: ':print a
 if w.lower()==a:print'Heresy! at index[%d]'%j if w==a else w

No regex, and Bonus 2


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.