Skip to content
Advertisement

Get ID from “ tag using a combined `.match` call

I have a string like this

JavaScript

And I just want to get the id value which is test_name. I use this code:

JavaScript

Is there any other ways to combine two match calls into one?

Advertisement

Answer

Use capturing group.

If the regular expression contain capturing group, String.prototype.match will return an array which contains whole matched string and captured groups:

JavaScript

You can get desired one by index:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement