1

When I run

var episode_pattern = /(?:EPISODE\:\s*\#)([0-9]*)/g; 
console.log(episode_pattern.exec("EPISODE:  #3"));  

I get back both the "EPISODE: #3" and the "3" in the matches.
However using the (?: I expected to only get "3" in the matches array.

1 Answer 1

4

The first element (element 0) of the returned array is always the entire matched string. In other words, if you have no groups at all, or if all your groups are non-capturing, you get back element 0. If you add groups without otherwise changing the regex, you still get back the same overall match in element 0, and then the groups start at element 1.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.