After several frustrating hours, I turn to the stackoverflow group for some help. While I know that regex can solve my problem, I do not know enough (and am on a deadline, so can’t learn what I need before the deadline) to do what I need to do.
My issue is that I have the following array:
(['ad53930','160x600','&PG=SPTRF3','&AP=1090','regular'],
['ad55852','728x90','&PG=SPTRF1','&AP=1390','regular'],
['ad52971','300x250_pginterstitial','&PG=SPTRF4','&AP=1089','pgInterstitial'],
['ad52969','300x250','&PG=SPTHP4','&AP=1089','regular'])
and need to extract the 6 digit code after the &PG=. I was able to hobble together some regex to pull the entire &PG=XXXXXX string, but built it in Chrome’s console, and after the browser crashed, lost the regex. What I am trying to accomplish is to get a finished product of ‘SPTRF3,SPTRF1,SPTRF4,SPTHP4’ from the array above, either in another array or string.
Any help would be greatly appreciated!
Why do you need regular expressions? You can just use a substring on that string in the array:
.substr(3).If the “&PG=” string is always in the array at index
2, then you can iterate through the array of arrays like this: