1

I want to create an array of matches for my regex expression in javascript.

It should look like: ['<:S_egirl:1023714296590499882>', '<a:eee:1023672889490284606>'] However, my code currently only makes an array with 1 item which includes all the matches.

The expression is: /<:.+:(\d+)>/gm

And my code is const parsed_emotes = [].concat(emotes.match(/<:.+:(\d+)>/gm)); console.log(parsed_emotes);

I've been stuck on this for hours, any help is appreciated.

1 Answer 1

2

Make your .+ non-greedy with ?. Compare the output of these two matches:

'<:hello:1234> <:hello:1234>'.match(/<:.+:(\d+)>/gm)
// Produces ['<:hello:1234> <:hello:1234>']

Vs a non-greedy match:

'<:hello:1234> <:hello:1234>'.match(/<:.+?:(\d+)>/gm)
// Produces ['<:hello:1234>', '<:hello:1234>']
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.