Some time back, I was comparing Perl and JavaScript in their Regular Expression Features. I thought it was not possible to get the holders after the matching in JavaScript like in Perl. But looks like there is something like that. A little known, use of RegExp global js object.
Like for example, You want to parse the phone number 201-123-1234 and hold area code and number in two separate variables for further use, you dont have to match it twice and replace once with area code and once with the remaining.
You could just do something like
I used this for a more complicated JDBC Connect String to SQL Plus Connect String converter (YEah, it may be less complex than I thought.)
Like for example, You want to parse the phone number 201-123-1234 and hold area code and number in two separate variables for further use, you dont have to match it twice and replace once with area code and once with the remaining.
You could just do something like
var e = "201-123-1234";
if(e.match(/([0-9]{3})-([0-9]{3})-([0-9]{4})/)){
var area = RegExp.$1;
var phone = RegExp.$2+""+RegExp.$3
}
I used this for a more complicated JDBC Connect String to SQL Plus Connect String converter (YEah, it may be less complex than I thought.)