1

I'm getting back in the swing of things and am stuck on this regular expression.

'2s3d3s'.match(/\d\D+/);

Why is this not returning ['2s, '3d', 3s']?

I specified the regex to capture multiple instances but it's only catching the first instance.

1 Answer 1

3

Use the /g modifier (used to perform a global match rather than stopping after the first match) to find all occurrences of a match.

console.log('2s3d3s'.match(/\d\D+/g));

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

2 Comments

So simple! Thanks a bunch. I'll mark it as correct in a few minutes. Thanks.
@DanRubio No problem.

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.