[Question]
  [
> 
> **Note:** The winning answer will be selected on **4/12/17** the current winner is [Jolf, 1 byte](https://codegolf.stackexchange.com/a/115323/58826).
> 
> 
> 
I'm surprised that we haven't had a what's my middle name challenge on this site yet. I did alot of searching but found nothing. If this is a dup, please flag it as such.
## Your challenge
Parse a string that looks like `Jo Jean Smith` and return `Jean`.
## Test cases
```
Input: Samantha Vee Hills
Output: Vee
Input: Bob Dillinger
Output: (empty string or newline)
Input: John Jacob Jingleheimer Schmidt
Output: Jacob Jingleheimer
Input: Jose Mario Carasco-Williams
Output: Mario
Input: James Alfred Van Allen
Output: Alfred Van 
```
(That last one is incorrect technically, but fixing that would be too hard.)
## Notes:
* Names will always have at least 2 space-separated parts, with unlimited middle names between them or can be a list/array of strings.
* Names may contain the alphabet (case-insensitive) and - (`0x2d`)
* You may output a trailing newline.
* You may require input to have a trailing newline.
* Input from STDIN, a function parameter, or command-line argument is allowed, but hard-coding it in is not allowed.
* Standard loopholes forbidden.
* Output may be function return value, STDOUT, STDERR, etc.
* Trailing spaces/newlines/tabs in the output are allowed.
* Any questions? Comment below!
**This is [code-golf](/questions/tagged/code-golf "show questions tagged 'code-golf'"), so the shortest anwser in bytes wins!**
  
[Answer]
# [Ohm](https://github.com/MiningPotatoes/Ohm), 2 bytes (CP437)
Accepts and returns a list of strings.
```
()
```
Explanation:
```
()   Main wire, arguments: a
(    Remove the first element of a
 )   ...and then the last element of that
     Implicit output
```
[Answer]
# Vim, ~~6~~ 5 bytes
```
dW$BD
```
[Try it online!](https://tio.run/nexus/v#@58SruLk8v@/V35GnoJXYnJ@koJXZl56TmpGamZuapFCcHJGbmZKCQA "V – TIO Nexus")
(outputs with a trailing space)
Since Vim is reverse-compatible with V, I have included a TIO link for V.
### Explanation
```
dW                      " Delete up to the next word (removes the first name)
$                       " Go to the end of the line
B                       " Go back one word
D                       " Delete it
```
[Answer]
# [Python](https://docs.python.org/), 24 bytes
```
lambda n:n.split()[1:-1]
```
[Try it online string input!](https://tio.run/nexus/python2#y7GN@Z@TmJuUkqiQZ5WnV1yQk1mioRltaKVrGPu/oCgzr0QhRyMzr6AUKKr5Xyk4MTcxryQjUSEsNVXBIzMnp1gJAA "Python 2 – TIO Nexus")
Input Format: **string**
  
# [Python 2](https://docs.python.org/2/), 16 bytes
```
lambda n:n[1:-1]
```
[Try it online list input!](https://tio.run/nexus/python2#y7GN@Z@TmJuUkqiQZ5UXbWilaxj7v6AoM69EIUcjM6@gtERDU/N/tFJwYm5iXklGopKOUlhqKpD0yMzJKVaKBQA "Python 2 – TIO Nexus")
Input Format: **List**
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 133 bytes
```
{{}((((()()()()){}){}){}[{}](<()>)){{}{}(<(())>)}{}}{}{({}<>)<>}<>{{}((((()()()()){}){}){}[{}](<()>)){{}{}(<(())>)}{}}{}{({}<>)<>}<>
```
[Try it online!](https://tio.run/nexus/brain-flak#@19dXasBApoQqFldC0HR1bWxGjYamnZAoepaoCIboBogD8gEomqN6lobO00bOyBJuQn//3vlZ@QpeCUm5ycpeGXmpeekZqRm5qYWKQQnZ@RmppT8100GAA "Brain-Flak – TIO Nexus")
132 bytes of code, plus 1 byte for the `-c` flag which allows ASCII input and output.
Unfortunately, this contains lots of duplicated code, but it would be really difficult to reuse. I'll look into it later. Here's an explanation:
```
#While True
{
    #Pop
    {}
    #Not equals 32
    ((((()()()()){}){}){}[{}](<()>)){{}{}(<(())>)}{}
#Endwhile
}
#Pop the 0
{}
#Reverse Stack
{({}<>)<>}<>
#While True
{
    #Pop
    {}
    #Not equals 32
    ((((()()()()){}){}){}[{}](<()>)){{}{}(<(())>)}{}
#Endwhile
}
#Pop the 0
{}
#Reverse Stack
{({}<>)<>}<>
```
[Answer]
# [05AB1E](https://github.com/Adriandmen/05AB1E), 2 bytes
```
¦¨
```
[Try it online!](https://tio.run/nexus/05ab1e#@39o2aEV//9Hq3vlZ@Sp66h7JSbnJ4HozLz0nNSM1Mzc1CIgNzg5IzczpUQ9FgA "05AB1E – TIO Nexus")
If outputting a list of middle names isn't allowed, I'll change it.
[Answer]
## Haskell, ~~23~~, ~~17~~ 9 bytes
```
init.tail
```
Takes and returns a list of strings. [Try it online!](https://tio.run/nexus/haskell#@59mm5mXWaJXkpiZ8z83MTNPwVahoCgzr0RBRSFNIVrJKz8jT0lHQckrMTk/CczIzEvPSc1IzcxNLQLxg5MzcjNTSpRi/wMA "Haskell – TIO Nexus")
Drop first string, drop last string. 
Edit: @Generic Display Name noted, that the input can be a list of strings, which saved 6 bytes.
Edit II: return list of strings instead of a single string
[Answer]
## Mathematica, 10 bytes
```
Rest@*Most
```
An unnamed function that accepts and returns a list of strings.
`Rest` discards the the last element, `Most` discards the first element, `@*` is function composition. Swapping `Rest` and `Most` or using right-composition `/*` instead would also work. This beats indexing via `#[[2;;-2]]&` by one byte.
[Answer]
# [Brain-Flak](https://github.com/DJMcMayhem/Brain-Flak), 86 bytes
```
(()()){({}[()]<{{}((((()()()()){}){}){}[{}](<()>)){{}{}(<(())>)}{}}{}{({}<>)<>}<>>)}{}
```
[Try it online!](https://tio.run/nexus/brain-flak#JYsxCsAgDEWv4pgMvUHwAK4dxaG1UoWqULqFnN3GNvl8fj4vAwABkYHFAwZiFpiD/yLLL88SgACtViwKkTJ6aVTNd7JIVv3rxnA9N@O22HfjSjuvlFOp6TZrzLUcz1jiCw "Brain-Flak – TIO Nexus")
Most of this code comes from [this answer](https://codegolf.stackexchange.com/a/114942/57100). If you like my solution you should upvote that one as well.
```
#Push 2
(()())
#Loop twice
{({}[()]<
  #While not a space
  {
      #Pop
      {}
      #Not equals 32
      ((((()()()()){}){}){}[{}](<()>)){{}{}(<(())>)}{}
  #Endwhile
  }
  #Pop the 0
  {}
  #Reverse Stack
  {({}<>)<>}<>
#End loop twice
>)}{}
```
[Answer]
# [AWK](https://www.gnu.org/software/gawk/manual/gawk.html), ~~17~~ 10 bytes
*Saved 7 bytes thanks to @steve!*
```
$NF=$1=x;1
```
[Try it online!](https://tio.run/nexus/awk#@6/i52arYmhbYW34/3@iQpJCskIKAA "AWK – TIO Nexus")
Explanation:
```
$NF=    set last word to
$1=     set first word to
x       an empty variable, ie empty string
1       default action, ie print everything
```
[Answer]
# Java 7, 74 bytes
```
String f(String s){return s.substring(s.indexOf(' '),s.lastIndexOf(' '));}
```
# Java 8, 49 bytes
```
s->s.substring(s.indexOf(' '),s.lastIndexOf(' '))
```
Function which identifies the first occurrence of the space character and the last one and extracts the middle. The resulting string is prefixed by a space character (at the time of the posting, OP hasn't clarified if leading spaces are allowed), which can be eliminated by adding `.trim()` to the code for an extra cost of 7 bytes.
Compared to C#, Java has the advantage of specifying the end index instead of sub-string length, which brings down the byte count.
[Answer]
## JavaScript (ES6), 22 bytes
Takes and outputs an array of strings.
```
([_,...a])=>a.pop()&&a
```
### Test cases
```
let f =
([_,...a])=>a.pop()&&a
console.log(f(["Samantha", "Vee", "Hills"]))
console.log(f(["Bob", "Dillinger"]))
console.log(f(["John", "Jacob", "Jingleheimer", "Schmidt"]))
console.log(f(["Jose", "Mario", "Carasco-Williams"]))
```
### String version (27 bytes)
Takes and outputs a string. The output string is either a single space if no middle name was found, or the middle names with leading and trailing spaces.
```
s=>(/ .* /.exec(s)||' ')[0]
```
```
let f =
s=>(/ .* /.exec(s)||' ')[0]
console.log(f("Samantha Vee Hills"))
console.log(f("Bob Dillinger"))
console.log(f("John Jacob Jingleheimer Schmidt"))
console.log(f("Jose Mario Carasco-Williams"))
```
[Answer]
# [Groovy](http://groovy-lang.org/), 19 bytes
```
{it.split()[1..-2]}
```
Explanation:
```
{        
 it                  all closures have an implicit argument called "it"
   .split()          splits by spaces by default. Returns an array of words
           [1..-2]   take the whole array from the second index (1) to the penultimate index (-2). Implicitly return
                  }
```
A closure / anonymous function
[Answer]
# Jolf, 1 byte
```
€
```
Gets the inside of the input. [Try it here!](http://conorobrien-foxx.github.io/Jolf/#code=4oKs&input=WyJKb25hdGhhbiIsICJWYW4iLCAiQWxsZW4iXQ)
[Answer]
# [Perl 5](https://www.perl.org/), 27 18 bytes
Need to run with `-n` option. 
```
/ (.+) /&&print$1
```
[Try it online!](https://tio.run/nexus/perl5#@6@voKGnramgr6ZWUJSZV6Ji@P@/V35GnoJXYnJ@koJXZl56TmpGamZuapFCcHJGbmZKyb/8gpLM/Lzi/7p5AA "Perl 5 – TIO Nexus")
Wanted to do something similar in sed first, but, unfortunately, it doesn't support non-greedy quantifier. It is needed in case middle name is more than one word.
**Edit**
-9 bytes thanks to **Dada**. 
Non-greedy quantifier is not needed anymore, among with some other things.
[Answer]
# PHP, 37 Bytes
```
<?=join(" ",array_slice($argv,2,-1));
```
-4 bytes for an output as array
```
print_r(array_slice($argv,2,-1));
```
## PHP, 42 Bytes
```
echo trim(trim($argn,join(range("!",z))));
```
## PHP, 50 Bytes
```
echo preg_filter("#(^[^\s]+ |[^\s]+$)#","",$argn);
```
[Answer]
# sed, ~~21~~ ~~19~~  ~~17~~  15 bytes + `-E`
new:
*idea thanks to @user41805*
*-2 thanks to @xigoi*
*-2 thanks to @ user41805*
```
s/^\S+ |\S+$//g
```
old:
*-1 thanks to @user41805*
```
s/\S+ ((.+ )*).+/\1/
```
[Try it online!](https://tio.run/##HcvNCkIhEIbhvVcxi3YhXkN/EEIr4bRpM@l0FHQ8OHb7mbV7eD8@oaBXfo8h5uH2YIz6Y2fMGA4Lco8ICxFcU86ijvUJ56nEKzVla2Sw6Ge0s2SKlAo1cD6WFPrcheCGLVU4YUPxVd9/ZyyiLBYSOORXowAL8mQm/tStp8oy9OUL/0A "sed – Try It Online")
[Answer]
## [Retina](https://github.com/m-ender/retina), 11 bytes
```
^\S+ |\S+$
```
[Try it online!](https://tio.run/nexus/retina#U9VwT/gfFxOsrVADJFS4/v8PTsxNzCvJSFQIS01V8MjMySnmcspPUnABsjLz0lOLuLzyM/IUvBKTgYJeQJGc1IzUzNzUIoXg5IzczJQSoHxxqoJvYlFmvoJzYlFicXK@bjhIc2JuMQA "Retina – TIO Nexus")
Matches the first word (including the space after it) and the last word, and removes both of them.
If I/O can be a linefeed-separated list, it can be done in 8 bytes instead:
```
A1`
G-2`
```
[Try it online!](https://tio.run/nexus/retina#FYs7CsMwEAV7neI1hjQq4hvkAzECVwKnSaGNslgL@oDk@ytyN8ww08U69NvVqZeeXf9khW4pUT4CYWPGIjE2dS9fPAdJ3rkqU0KGIT@kGSZyYElcYX1I8jtGb4yVqhQ8qFLzRb/PmVL7Aw)
[Answer]
# Javascript (ES6) ~~49~~ 16 bytes
## **Edit:**
```
a=>a.slice(1,-1)
```
[Try it online!](https://tio.run/nexus/javascript-node#S7P9X2FrV6FXnJOZnKphqKNrqPk/OT@vOD8nVS8nP10jTSNaKTgxNzGvJCNRSUdBKSw1FUR5ZObkFCvFampyoSt2yk8CKXABKsjMS08twqrIKz8jD6TKKzEZotwLqDYnNSM1MxeoA8gPTs7IzUwpwaG5GOwG38SizHwQwzmxKLE4OV83HGRnYi7YXf8B "JavaScript (Node.js) – TIO Nexus")
**ungolfed:**
```
function(name) {
  return a.slice(1, -1); //start at the second item and end at the second to last item
};
```
I forgot some of the simple properties of [`slice`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/slice), and that the input can be an array. Thanks to @Neil and @fəˈnɛtɪk I was able to remove 27 bytes. Still not really competing.
## **Original:**
This isn't really competing but here's a Javascript solution:
```
a=>{a=a.split(' ');return a.slice(1, a.length-1)}
```
This creates an anonymous function equal to:
```
function(name) {
  let name = name.split(' '); //first middle last -> [first, middle, last]
  return name.slice(1, name.length - 1); //get the second item to the second to last item in the array.
}
```
### How I golfed it
This is a pretty simple golf. I turned the function into an [arrow function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/Arrow_functions). Then I "minified" the code. This included renaming `name` into a single character(`a` in this case) and removing the `let` decloration of the variable.
### Snippet
```
var a=b=>b.slice(1,-1)
//example code
let form = document.querySelector('#form'),
    input = document.querySelector('#input'),
    result = document.querySelector('#result');
form.addEventListener('submit', (event) => {
  event.preventDefault();
  let value = input.value.split` `;
  result.textContent = a(value).join(' ');
});
```
```
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
<form id="form">
  <div class="input-group">
    <input id="input" class="form-control" />
    <div class="input-group-btn">
      <button class="btn btn-primary">Submit</button>
    </div>
  </div>
</form>
<p id="result"></p>
```
Hope this helps anyone who is stuck on the challenge.
[Answer]
# [Arn](https://github.com/ZippyMagician/Arn), [4 bytes](https://github.com/ZippyMagician/Arn/wiki/Carn)
```
†Û⁺%
```
[Try it!](https://zippymagician.github.io/Arn?code=LnsufQ==&input=U2FtYW50aGEgVmVlIEhpbGxzCkJvYiBEaWxsaW5nZXIKSm9obiBKYWNvYiBKaW5nbGVoZWltZXIgU2NobWlkdApKb3NlIE1hcmlvIENhcmFzY28tV2lsbGlhbXM=)
# Explained
Unpacked: `.{.}`
```
_ Variable initialized to STDIN; implied
  .{ Take
    .} Then drop
         Output implicit
```
Strings are split on spaces if any or ever character if there are non (when casted to an array).
[Answer]
# [Husk](https://github.com/barbuz/Husk), ~~6~~ 4 bytes
```
;htw
```
[Try it online!](https://tio.run/##yygtzv7/3zqjpPz///9e@Rl5Cl6JyflJCl6Zeek5qRmpmbmpRQrByRm5mSklAA "Husk – Try It Online")
-2 bytes from Zgarb.
[Answer]
# [Röda](https://github.com/fergusq/roda), 9 bytes
```
{_[1:-1]}
```
[Try it online!](https://tio.run/nexus/roda#JYuxCsIwGIRn8xRHZot0VVzUQQqdCjq0pfzGvybQJJLUqfbZa4rDwd13d5aMw4T@2CxTV@f7LG/nZTOhdmR5JyFbfNEnvT9Ro9siocM/yMZJzOh9wDoW81KRJTdqwo0ZVzMMUZz8A5fkjHtxEIXXDgWpBItEBtZsLAdUSlvzHFMfGSUF43GmQFH57L6eycYf "Röda – TIO Nexus")
Not a very interesting solution. Takes a list from the stream and returns the middle names.
21 bytes and I/O:
```
{[(_/" ")[1:-1]&" "]}
```
[Try it online!](https://tio.run/nexus/roda#FYu9CsJAEAZr7yk@UogWQdIKNmohAauAFjGENW68hfuRu3Qxz36e3TDDWBKHGePhkeZ20@8KFNu22pdVt87YLWk14otPEDehV0tqyJKbNOHGjIsYE9XRP3HOJO7NQdVeO9Q0ZFlnY1izWA5oBm3lNeUeGVcK4nGiQHHw5f0/k40/ "Röda – TIO Nexus")
This uses `/` (split) and `&` (join).
[Answer]
# [Jelly](https://github.com/DennisMitchell/jelly), 2 bytes
```
ḊṖ
```
[Try it online!](https://tio.run/nexus/jelly#@/9wR9fDndP@//@v7pWfkaeuo@6VmJyfBKIz89JzUjNSM3NTi4Dc4OSM3MyUEnUA "Jelly – TIO Nexus")
This works as a non-inline link (i.e. function), not a full program.
`'John','Jacob','Jingleheimer','Schmidt'` → `'Jacob','Jingleheimer'`
As a full program, it would be 3 bytes: `ḊṖK`, which prints a space-separated middle name.
[Answer]
# Pyth, 2 bytes
```
Pt
```
[Online interpreter](//pyth.herokuapp.com?code=Pt&input=%5B%27John%27%2C%27Jacob%27%2C%27Jingleheimer%27%2C%27Schmidt%27%5D)
[Answer]
# C#, 67 bytes
```
s=>s.Substring(s.IndexOf(' ')+1,s.LastIndexOf(' ')-s.IndexOf(' '));
```
Anonymous function which identifies the first occurrence of the space character and the last one and extracts the middle. It also extracts a trailing space, which can be removed at the cost of 2 bytes.
Full program with test cases:
```
using System;
namespace WhatsMyMiddleName
{
    class Program
    {
        static void Main(string[] args)
        {
            Func<string, string> f =
            s=>s.Substring(s.IndexOf(' ')+1,s.LastIndexOf(' ')-s.IndexOf(' '));
            Console.WriteLine(f("Jo Jean Smith"));          // "Jean"
            Console.WriteLine(f("Samantha Vee Hills"));     // "Vee"
            Console.WriteLine(f("Bob Dillinger"));          // ""
            Console.WriteLine(f("John Jacob Jingleheimer Schmidt"));// "Jacob Jingleheimer"
            Console.WriteLine(f("Jose Mario Carasco-Williams"));    // "Mario"
            Console.WriteLine(f("James Alfred Van Allen")); // "Alfred Van"
        }
    }
}
```
[Answer]
# [Kotlin](https://kotlinlang.org), 39 bytes
```
s.filterIndexed{i,j->i!=0&&i!=s.size-1}
```
[Try it online!](https://tio.run/nexus/kotlin#PY1PC4IwGMbP@SnWDrKBSl0lhY5J0MFPsNw7fWXO2BasxM9uq0OXh98Dzx/1NCQwV17R@VPrLZq@5qTaXKFQe7AXIyGAXDAb8xr31SFNo7rC4Rvy47qp2J8EGiZs70pytla8/jtLsntE8tqwwHR8uClGm3kwNCO0Ed18/0HMahgAJ7Bf33bDhNJTznmybh8 "Kotlin – TIO Nexus")
i.e.
```
s.filterIndexed{ index, value -> index != 0 && index != (s.size - 1) }
```
[Answer]
# VBA, 69 bytes
```
Sub m(n)
f=InStr(1,n," ")
Debug.?Mid(n,f+1,InStrRev(n," ")-f)
End Sub
```
[Answer]
## [Grime](https://github.com/iatorm/grime), 6 bytes
```
<\ 0\ 
```
[Try it online!](https://tio.run/nexus/grime#@28To2AQo/D/f3pWeoZCWnpGmUJ6egYA "Grime – TIO Nexus")
Note the trailing space.
## Explanation
```
        Match a substring S that satisfies:
<       S is contained in a string of the form
 \      a space
   0    then S
    \   then another space.
```
This matches a substring that's surrounded by spaces.
By default, Grime prints the longest match it finds (without the spaces).
If no match exists, nothing is printed.
[Answer]
# R, ~~30~~ ~~27~~ 22 bytes
Current solution due to user11599!
```
head(scan(,''),-1)[-1]
```
Takes input from stdin, returns each middle name as a separate string. Returns `character()` in the case of no middle name; that is, a vector of class `character` of length `0`.
**Explanation:**
Read stdin into a list of strings, separated by spaces
```
     scan(,'')
```
Remove the last element. `head` returns the first `n` elements of a list, with `n` defaulting to `6`. If `n` is `-1` it returns all but the last element.
```
head(scan(,''),-1)
```
Now, remove the first element of this list.
```
head(scan(,''),-1)[-1]
```
This yields the middle name(s).
[Answer]
# Ruby, ~~24~~ 13 bytes
```
p ARGV[1..-2]
```
*Saved 11 bytes thanks to Piccolo pointing out that array-like output is allowed.*
Takes the name as separate command line arguments, e.g.:
```
$ ruby script.rb John Jacob Jingleheimer Schmidt
```
or
```
$ ruby -e 'p ARGV[1..-2]' John Jacob Jingleheimer Schmidt
```
---
Previous code (outputs a proper string):
```
puts ARGV[1..-2].join" "
```
[Answer]
# **Golang**, ~~152~~ 81 bytes
```
import ."strings"
func f(x string)[]string{var k=Fields(x);return k[1:len(k)-1];}
```
It takes input as "Samantha Vee Hills" (with double quotes) and return the middle name to the stdout.
[Try it Online!](https://tio.run/nexus/go#NY2xCoMwGIRn8xQ/gZYEWsG10rV0LAhdxCHYxIYkf20SiyA@u9Vqt7vvuLtW1EY0EpzQSLRrXz4CVS7SaTMpDdFrbAIlqsMaFOthJbysVjF8hAdzvmhpH4H1PPcydh7BlNnJSmSGH7MqH6dffzliHAaSLC3ctkgyf6ZFLVAxunvTA@yRr/A25/FPFUPOyTjRQjiB8SngLiVctbWBfgE "Try it online!")
Edit: @Dada, note that the "function as answer is allowed" shorten my code 71 bytes. a big thanks!
]