Q:

Regex for a fill-in-the-blank type string

I have a string with a known beginning and end, but I want to match only the unknown center. 
For example, say you knew you were going to have strings which said 
"I had ________ for lunch today" and you only wanted to match the blank. 
Here's what I have tried:
^I had (.*) for lunch today$
Which matches the entire string, and also the group, which is the blank.
So when given "I had pizza for lunch today" it produces two matches:
"I had pizza for lunch today" and "pizza"
Is there any way to only match the blank? Is there any way to just get "pizza"? Or at least get "pizza" as the first match?

A:

You constructed a capturing group; use it.
When you create a regular expression with something wrapped in parentheses, in your case (.*?), you have created a capturing group. Whatever is matched by capturing groups will be returned alongside the full match.
String.prototype.match() returns an array. Its first element is the full match. All subsequent elements are captured results. Since you only have one capturing group, the result is matches[1].

var sentences = [
    "I had pizza for lunch today",
    "I had hamburger for lunch today",
    "I had coconut for lunch today",
    "I had nothing for lunch today"
];

sentences.map(function(sentence) {
   console.log(sentence + " -> " + sentence.match(/^I had (.*?) for lunch today$/)[1])
})

