ni******@gmail.com wrote:
123ABC123 =123ABC, 123
343BBB =343BBB, null
12323 =null, 12322
(?<first>.*\D+)(?<second>\d*) doesn't work on the third line.
Try:
var data = {
x : '123ABC456',
y : '343BBB',
z : '12345'
};
var p, t, u,
re = /(^\d+[^\d]+|^.*?)(\d*$)/g;
for (p in data) {
u = [];
while (t = re.exec(data[p])) {
u[0] = t[1] || null;
u[1] = t[2] || null;
}
alert('String: ' + data[p] + '\n\n' + u.join(' : '));
}
You could also use:
re = /(^\d+[^\d]+|^)(\d*$)/g;
or if ^\d doesn't suit (it will match any non-digit):
re = /(^\d+[A-Z]+|^)(\d*$)/g;
or
re = /(^\d+[a-z]+|^)(\d*$)/ig;
may be safer - take your pick. Tested in Safari, Firefox and Opera.
--
Rob
"We shall not cease from exploration, and the end of all our
exploring will be to arrive where we started and know the
place for the first time." -- T. S. Eliot