Sunday, October 16, 2011

Javascript (remove character outside bracket)

i want to extract some information from text
for example. My Name Is Abu (19) years old

final output is 19

searching thru i found this code


pattern = /([a-z]+)([0-9]+)([A-Z]+)([0-9]+)/;
subject = 'test1234TEST1234';
matches = subject.match(pattern);
match1 = matches[1];
match2 = matches[2];
match3 = matches[3];
match4 = matches[4];
alert(match1);
alert(match2);
alert(match3);
alert(match4);

this is near but cannot add spaces or bracket on regex search

finally i remove space using this code


bb = "AAA AAA AAA(asdasd0 )asdasd asdasd";alert(bb.replace(/[\(\) ]/g,""));



reference: http://lawrence.ecorp.net/inet/samples/regexp-format.php


No comments:

Related Posts Plugin for WordPress, Blogger...