Hi all
My first post so bare with me!
This is a javascript question
Is it possible to use regex in a form to match the first match then behind the scenes. Match all occurrences (there could be like many identical matches) and copy them into a javascript array feeding them into a pull down form.
(AJAX style)
so say a regex of
123(.*)abc
with content like this
123Eabc
123Fabc
123Gabc
123Habc
123Iabc
The javascript array would contain
0->E
1->F
2->G
3->H
4->I
Then these results displayed in a pulldown form
Any help or advice (or even solution would be most appreciated)
Thanks
javascript regex multiple matches into a javascript array
Moderator: General Moderators
- Kieran Huggins
- DevNet Master
- Posts: 3635
- Joined: Wed Dec 06, 2006 4:14 pm
- Location: Toronto, Canada
- Contact:
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
It goes something like this:
Code: Select all
var backRefs = new Array();
var testString = '123Aabc\n' +
'123Babc\n' +
'123Cabc\n' +
'123Dabc\n' +
'123Eabc\n';
var re = /123(.*?)abc/g;
var matches;
while (matches = re.exec(testString)) {
backRefs.push(matches);
}
/*
Array (
0 => Array (
0 => 123Aabc,
1 => A
),
Array (
0 => 123Babc,
1 => B
),
Array (
0 => 123Cabc,
1 => C
),
Array (
0 => 123Dabc,
1 => D
),
Array (
0 => 123Eabc,
1 => E
)
)
*/