[Question]
  [
Earlier this week, we learned about how to [format esoteric languages](https://codegolf.stackexchange.com/questions/92776/esolang-comment-template-generator) for commenting. Today, we're going to do the inverse of that. I need you to write a program or function that parses some well-commented esoteric code and parses the comments out, returning just the code. Using some examples from the previous challenge, here is what well-commented code looks like:
```
a                #Explanation of what 'a' does
 bc              #Bc
   d             #d
    e            #Explanation of e
     fgh         #foobar
        ij       #hello world
          k      #etc.
           l     #so on
            mn   #and
              op #so forth
```
Here is what you need to do to extract the code out. First, remove the comment character (`#`), the space before it, and everything after the comment character.
```
a               
 bc             
   d            
    e           
     fgh        
        ij      
          k     
           l    
            mn  
              op
```
Then, collapse each line upwards into a single line. For example, since `b` is in the second column on line two, once we collapse it up, it will be in the second column on line *one*. Similarly, `c` will be put in the third column of line one, and `d` will be put on the fourth. Repeat this for every character, and you get this:
```
abcdefghijklmnop
```
Important note: It seems like the trivial solution is to just remove the comments, remove every space, and join every line. This is *not* a valid approach! Because the original code might have spaces in it, these will get stripped out with this approach. For example, this is a perfectly valid input:
```
hello         #Line one
              #Line two
       world! #Line three
```
And the corresponding output should be:
```
hello  world!
```
# The Challenge:
Write a program or function that takes commented code as input, and outputs or returns the code with all the comments parsed out of it. You should output the code *without* any trailing spaces, although one trailing newline is permissible. The comment character will always be `#`, and there will always be one extra space before the comments start. `#` will *not* appear in the comment section of the input. In order to keep the challenge simpler, here are some inputs you do *not* have to handle:
* You can assume that the code will not have two characters in the same column. For example, this is an input that violates this rule:
```
a  #A character in column one
bc #Characters in columns one and two
```
* You can also assume that all comment characters appear in the same column. For example, this input:
```
short       #this is a short line
      long        #This is a long line
```
violates this rule. This also means that `#` will not be in the code section.
* And lastly, you do not have to handle code sections with leading or trailing spaces. For example,
```
  Hello,          #
         World!   #
```
You may also assume that the input only contains printable ASCII characters.
# Examples:
```
Input:
hello         #Line one
              #Line two
       world! #Line three
Output:
hello  world!
Input:
E                                                   #This comment intentionally left blank
 ac                                                 #
   h s                                              #
      ecti                                          #
          on is                                     #
                one c                               #
                     haracte                        #
                            r longer                #
                                     than the       #
                                              last! #
Output:
Each section is one character longer than the last!
Input:
4          #This number is 7
 8         #
  15       #That last comment is wrong.
    16     #
      23   #
        42 #
Output:
4815162342
Input:
Hello                     #Comment 1
      world               #Comment 2
           ,              #Comment 3
             how          #Comment 4
                 are      #Comment 5
                     you? #Comment 6
Output:
Hello world, how are you?
Input:
Prepare                               #
        for...                        #
                        extra spaces! #
Output:
Prepare for...          extra spaces!
```
You may take input in whatever reasonable format you like, for example, a list of strings, a single string with newlines, a 2d list of characters, etc. The shortest answer in bytes wins!
  
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), ~~8~~ 7 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
»/ṣ”#ḢṖ
```
[Try it online!](http://jelly.tryitonline.net/#code=wrsv4bmj4oCdI-G4ouG5lgrhu7TDhyAgICAgIOG4t-KAnCBTcGxpdCBhdCBuZXdsaW5lcyBhbmQgY2FsbCB0aGUgbGluayBhYm92ZS4&input=&args=SGVsbG8gICAgICAgICAgICAgICAgICAgICAjQ29tbWVudCAxCiAgICAgIHdvcmxkICAgICAgICAgICAgICAgI0NvbW1lbnQgMgogICAgICAgICAgICwgICAgICAgICAgICAgICNDb21tZW50IDMKICAgICAgICAgICAgIGhvdyAgICAgICAgICAjQ29tbWVudCA0CiAgICAgICAgICAgICAgICAgYXJlICAgICAgI0NvbW1lbnQgNQogICAgICAgICAgICAgICAgICAgICB5b3U_ICNDb21tZW50IDY)
### How it works
```
»/ṣ”#ḢṖ  Main link. Argument: A (array of strings)
»/       Reduce the columns of A by maximum.
         Since the space is the lowest printable ASCII characters, this returns the
         non-space character (if any) of each column.
  ṣ”#    Split the result at occurrences of '#'.
     Ḣ   Head; extract the first chunk, i.e., everything before the (first) '#'.
      Ṗ  Pop; remove the trailing space.
```
[Answer]
# Python 2, ~~48~~ 43 bytes
```
lambda x:`map(max,*x)`[2::5].split(' #')[0]
```
*Thanks to @xnor for golfing off 5 bytes!*
Test it on [Ideone](http://ideone.com/UslRUT).
[Answer]
# JavaScript (ES6), ~~97~~ ~~75~~ 60 bytes
Thanks to [@Neil](https://codegolf.stackexchange.com/users/17602/neil) for helping golf off 22 bytes
```
a=>a.reduce((p,c)=>p.replace(/ /g,(m,o)=>c[o])).split` #`[0]
```
Input is an array of lines.
* `a` is array input
* `p` is previous item
* `c` is current item
* `m` is match string
* `o` is offset
[Answer]
# Perl, ~~35~~ ~~34~~ 32 bytes
Includes +1 for `-p`
Give input on STDIN
`eso.pl`
```
#!/usr/bin/perl -p
y/ /\0/;/.#/;$\|=$`}{$\=~y;\0; 
```
Notice that there is a space after the final `;`. The code works as shown, but replace `\0` by the literal character to get the claimed score.
[Answer]
## Python 2, 187 bytes
```
def f(x,o=""):
 l=[i[:i.index("#")-1]for i in x]
 for n in range(len(l[0])):
  c=[x[n]for x in l]
  if sum([1for x in c if x!=" "])<1:o+=" "
  else:o+=[x for x in c if x!=" "][0]
 print o
```
I'm gonna golf this more tomorrow I have school ;)
[Answer]
# Ruby, 63 bytes
Basically a port of [Dennis' Jelly answer](https://codegolf.stackexchange.com/a/93068/11261). Takes input as an array of strings.
```
->a{l,=a
l.gsub(/./){a.map{|m|m[$`.size]||$/}.max}[/(.+) #/,1]}
```
See it on eval.in: <https://eval.in/640757>
[Answer]
## [CJam](http://sourceforge.net/projects/cjam/), 12 bytes
*Thanks to Sp3000 for saving 2 bytes.*
```
{:.e>_'##(<}
```
An unnamed block that takes a list of strings (one for each line) and replaces it with a single string.
[Try it online!](http://cjam.tryitonline.net/#code=WyJoZWxsbyAgICAgICAgICNMaW5lIG9uZSIKICIgICAgICAgICAgICAgICNMaW5lIHR3byIKICIgICAgICAgd29ybGQhICNMaW5lIHRocmVlIl0KCns6LmU-XycjIyg8fQoKfg&input=aGVsbG8gICAgICAgICAjTGluZSBvbmUKICAgICAgICAgICAgICAjTGluZSB0d28KICAgICAgIHdvcmxkISAjTGluZSB0aHJlZQ)
### Explanation
```
:.e>  e# Reduce the list of strings by elementwise maximum. This keeps non-spaces in
      e# favour of spaces. It'll also wreak havoc with the comments, but we'll discard
      e# those anyway.
_'##  e# Duplicate and find the index of '#'.
(<    e# Decrement that index and truncate the string to this length.
```
[Answer]
# J, 30 bytes
```
(#~[:<./\'#'~:])@(>./&.(3&u:))
```
Takes a list of strings as input. Basically uses the same approach as Dennis in his Jelly answer.
## Commented and explained
```
ord =: 3 & u:
under =: &.
max =: >./
over =: @
maxes =: max under ord
neq =: ~:
arg =: ]
runningMin =: <./\
magic =: #~ [: runningMin ('#' neq arg)
f =: magic over maxes
```
Intermediate steps:
```
   p
Hello                     #Comment 1
      world               #Comment 2
           ,              #Comment 3
             how          #Comment 4
                 are      #Comment 5
                     you? #Comment 6
   maxes p
Hello world, how are you? #Comment 6
   magic
#~ ([: runningMin '#' neq arg)
   3 neq 4
1
   '#' neq '~'
1
   '#' neq '#'
0
   '#' neq maxes p
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1 1 1 1
   runningMin 5 4 2 5 9 0 _3 4 _10
5 4 2 2 2 0 _3 _3 _10
   runningMin '#' neq maxes p
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0
   0 1 0 1 1 0 # 'abcdef'
bde
   'abcdef' #~ 0 1 0 1 1 0
bde
   (maxes p) #~ runningMin '#' neq maxes p
Hello world, how are you? 
   (#~ [: runningMin '#' neq arg) maxes p
Hello world, how are you? 
   ((#~ [: runningMin '#' neq arg) over maxes) p
Hello world, how are you? 
   (magic over maxes) p
Hello world, how are you? 
```
## Test case
```
   f =: (#~[:<./\'#'~:])@(>./&.(3&u:))
   a
Hello                     #Comment 1
      world               #Comment 2
           ,              #Comment 3
             how          #Comment 4
                 are      #Comment 5
                     you? #Comment 6
   $a
6 36
   f a
Hello world, how are you?
```
[Answer]
# Javascript (ES6), 63 bytes
```
a=>a.reduce((p,c)=>p+/(.+?)\s+#/.exec(c)[1].slice(p.length),'')
```
Takes input as an array of strings.
```
F=a=>a.reduce((p,c)=>p+/(.+?)\s+#/.exec(c)[1].slice(p.length),'')
input.oninput = update;
update();
function update() {
  try {
    output.innerHTML = F(input.value.trim().split`
`);
  } catch(e) {
    output.innerHTML = 'ERROR: INVALID INPUT';
  }
}
```
```
textarea {
  width: 100%;
  box-sizing: border-box;
  font-family: monospace;
}
```
```
<h2>Input:</h2>
<textarea id="input" rows="8">
a                #Explanation of what 'a' does
 bc              #Bc
   d             #d
    e            #Explanation of e
     fgh         #foobar
        ij       #hello world
          k      #etc.
           l     #so on
            mn   #and
              op #so forth
</textarea>
<hr />
<h2>Output:</h2>
<pre id="output">
</pre>
```
[Answer]
# [Retina](http://github.com/mbuettner/retina), 32 bytes
Byte count assumes ISO 8859-1 encoding.
```
Rmr` #.+|(?<=^(?<-1>.)+).+?¶( )+
```
[Try it online!](http://retina.tryitonline.net/#code=Um1yYCAjLit8KD88PV4oPzwtMT4uKSspLis_wrYoICkr&input=YSAgICAgICAgICAgICAgICAjRXhwbGFuYXRpb24gb2Ygd2hhdCAnYScgZG9lcwogYmMgICAgICAgICAgICAgICNCYwogICBkICAgICAgICAgICAgICNkCiAgICBlICAgICAgICAgICAgI0V4cGxhbmF0aW9uIG9mIGUKICAgICAgICAgICAgICAgICAjZm9vYmFyCiAgICAgICAgaWogICAgICAgI2hlbGxvIHdvcmxkCiAgICAgICAgICAgICAgICAgI2V0Yy4KICAgICAgICAgICBsICAgICAjc28gb24KICAgICAgICAgICAgbW4gICAjYW5kCiAgICAgICAgICAgICAgb3AgI3NvIGZvcnRo)
[Answer]
## Pyke, ~~15~~ 10 bytes
```
,FSe)s\#ch
```
[Try it here!](http://pyke.catbus.co.uk/?code=%2CFSe%29s%5C%23ch&input=%22Prepare+++++++++++++++++++++++++++++++%23+comment+1%22%2C%22++++++++for...++++++++++++++++++++++++%23+comment+2%22%2C%22++++++++++++++++++++++++extra+spaces%21+%23+comment+3%22)
Port of the Jelly answer
```
,          -     transpose()
 FSe)      -    map(min, ^)
     s     -   sum(^)
      \#c  -  ^.split("#")
         h - ^[0]
```
[Answer]
# C# 157 122 Bytes
Golfed 35 bytes thanks to @milk -- though I swear I tried that earlier.
Takes input as a 2-d array of characters. 
```
string f(char[][]s){int i=0;foreach(var x in s)for(i=0;x[i]!=35;i++)if(x[i]!=32)s[0][i]=x[i];return new string(s[0],0,i);}
```
157 bytes:
```
string g(char[][]s){var o=new char[s[0].Length];foreach(var x in s)for(int i=0;x[i]!=35;i++)if(x[i]!=32|o[i]<1)o[i]=x[i];return new string(o).TrimEnd('\0');}
```
[Answer]
# Pyth, 11 bytes
```
PhceCSMCQ\#
```
A program that takes input of a list of strings on STDIN and prints a string.
[Try it online](https://pyth.herokuapp.com/?code=PhceCSMCQ%5C%23&test_suite=1&test_suite_input=%5B%27hello+++++++++%23Line+one%27%2C+%27++++++++++++++%23Line+two%27%2C+%27+++++++world%21+%23Line+three%27%5D%0A%5B%27E+++++++++++++++++++++++++++++++++++++++++++++++++++%23This+comment+intentionally+left+blank%27%2C+%27+ac+++++++++++++++++++++++++++++++++++++++++++++++++%23%27%2C+%27+++h+s++++++++++++++++++++++++++++++++++++++++++++++%23%27%2C+%27++++++ecti++++++++++++++++++++++++++++++++++++++++++%23%27%2C+%27++++++++++on+is+++++++++++++++++++++++++++++++++++++%23%27%2C+%27++++++++++++++++one+c+++++++++++++++++++++++++++++++%23%27%2C+%27+++++++++++++++++++++haracte++++++++++++++++++++++++%23%27%2C+%27++++++++++++++++++++++++++++r+longer++++++++++++++++%23%27%2C+%27+++++++++++++++++++++++++++++++++++++than+the+++++++%23%27%2C+%27++++++++++++++++++++++++++++++++++++++++++++++last%21+%23%27%5D%0A%5B%274++++++++++%23This+number+is+7%27%2C+%27+8+++++++++%23%27%2C+%27++15+++++++%23That+last+comment+is+wrong.%27%2C+%27++++16+++++%23%27%2C+%27++++++23+++%23%27%2C+%27++++++++42+%23%27%5D%0A%5B%27Hello+++++++++++++++++++++%23Comment+1%27%2C+%27++++++world+++++++++++++++%23Comment+2%27%2C+%27+++++++++++%2C++++++++++++++%23Comment+3%27%2C+%27+++++++++++++how++++++++++%23Comment+4%27%2C+%27+++++++++++++++++are++++++%23Comment+5%27%2C+%27+++++++++++++++++++++you%3F+%23Comment+6%27%5D%0A%5B%27Prepare+++++++++++++++++++++++++++++++%23%27%2C+%27++++++++for...++++++++++++++++++++++++%23%27%2C+%27++++++++++++++++++++++++extra+spaces%21+%23%27%5D&debug=0)
**How it works**
```
PhceCSMCQ\#  Program. Input: Q
       CQ    Transpose Q
     SM      Sort each element of that lexicographically
    C        Transpose that
   e         Yield the last element of that, giving the program ending with ' #' and some
             parts of the comments
  c      \#  Split that on the character '#'
 h           Yield the first element of that, giving the program with a trailing space
P            All but the last element of that, removing the trailing space
             Implicitly print
```
[Answer]
# sed, 126 bytes
```
:a;N;$!ba;s,#[^\n]*\n,#,g;s,^,#,;:;/#[^ ]/{/^# /s,^# *,,;t;H;s,#.,#,g}
t;/#[^ ]/!{H;s,#.,#,g};t;g;s,\n#(.)[^\n]*,\1,g;s,...$,,
```
Requires a newline at the end of the input.  
I'm sure I can golf this a little more, but I'm just happy it works for now.
[Answer]
# [Perl 6](http://perl6.org/), 39 bytes
```
{[Zmax](@_».comb).join.split(' #')[0]}
```
Translation of the [Python solution by Dennis](https://codegolf.stackexchange.com/a/93072/14880).  
Takes input as a list of strings, and returns a string.
([try it online](https://glot.io/snippets/eifhpqhiu3))
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 27 [bytes](https://github.com/DennisMitchell/jelly/wiki/Code-page)
```
żḟ€” ;€” Ḣ€
i€”#’©ḣ@"ç/ḣ®ṪṖ
```
Test it at **[TryItOnline](http://jelly.tryitonline.net/#code=xbzhuJ_igqzigJ0gO-KCrOKAnSDhuKLigqwKaeKCrOKAnSPigJnCqeG4o0Aiw6cv4bijwq7huarhuZY&input=&args=IlByZXBhcmUgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIyBjb21tZW50IDEiLCIgICAgICAgIGZvci4uLiAgICAgICAgICAgICAgICAgICAgICAgICMgY29tbWVudCAyIiwiICAgICAgICAgICAgICAgICAgICAgICAgZXh0cmEgc3BhY2VzISAjIGNvbW1lbnQgMyI)**
Uses the strictest spec - the extra space before the comment character is removed at the cost of a byte.
Input is a list of strings.
[Answer]
## Ruby, 77 bytes
```
puts File.readlines("stack.txt").join('').gsub(/\s{1}#.*\n/,'').gsub(/\s/,'')
```
[Answer]
# TSQL, ~~216~~ 175 bytes
**Golfed:**
```
DECLARE @ varchar(max)=
'hello         #Line one
              #Line two
       world! #Line three'
DECLARE @i INT=1,@j INT=0WHILE @i<LEN(@)SELECT @=stuff(@,@j+1,len(x),x),@j=iif(x=char(10),0,@j+1),@i+=1FROM(SELECT ltrim(substring(@,@i,1))x)x PRINT LEFT(@,patindex('%_#%',@))
```
**Ungolfed:**
```
DECLARE @ varchar(max)=
'hello         #Line one
              #Line two
       world! #Line three'
DECLARE @i INT=1,@j INT=0
WHILE @i<LEN(@)
  SELECT @=stuff(@,@j+1,len(x),x),@j=iif(x=char(10),0,@j+1),@i+=1
  FROM(SELECT ltrim(substring(@,@i,1))x)x
PRINT LEFT(@,patindex('%_#%',@))
```
**[Fiddle](https://data.stackexchange.com/stackoverflow/query/539127/parse-the-comments-out-of-my-esoteric-code)**
[Answer]
# [Dyalog APL](http://goo.gl/9KrKoM), 22 [bytes](https://codegolf.meta.stackexchange.com/a/9429/43319)
[Inspiration](https://codegolf.stackexchange.com/a/93068/43319).
```
(⎕UCS¯2↓⍳∘35↑⊢)⌈⌿∘⎕UCS
```
`(`
 `⎕UCS` character representation of
 `¯2↓` all but the last two of
 `⍳∘35↑` up until the position of the first 35 ("#"), in that which is outside the parenthesis, taken from
 `⊢` that which is outside the parenthesis
`)` namely...
`⌈⌿` the columnar maximums
`∘` of
`⎕UCS` the Unicode values
[TryAPL online!](http://tryapl.org/?a=f%u2190%28%u2395UCS%AF2%u2193%u2373%u221835%u2191%u22A2%29%u2308%u233F%u2218%u2395UCS%20%u22C4%20%u22A2Input%u2190%u2191%27hello%20%20%20%20%20%20%20%20%20%23Line%20one%27%20%27%20%20%20%20%20%20%20%20%20%20%20%20%20%20%23Line%20two%27%20%27%20%20%20%20%20%20%20world%21%20%23Line%20three%27%20%u22C4%20f%20Input&run)
]