medev21 medev21 - 1 year ago 96
Javascript Question

grab number from an array of string - regex - javascript

I have an array of strings; they are URLs. I would like to grab a specific number from each URL.

These urls are in this format:


I would like to grab the fifth digit code after
, which is
. Keep in mind the fifth digit code and the other ones can be any random number, it's not always zeros or ones.

Array sample:


Like I said, I have an array of url strings and trying to figure it out how to grab the fifth digit code using Javascript; regex could help me achieve this but I'm not familiar w/ regex.

I was told python could be easier to solve this, but I'm building a chrome ext. which is using JS.

Thanks for your help in advance!

Answer Source

You could do it without Regex with just split() chained with apropriate index choice :

var addresses = ["",
var results = => x.split("?")[1].split("&")[0].split("-")[4])

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download