javascript에서 정규식 사용



match(), test(), new RegExp("pattern","flags")


matchedValue = /pattern/.exec(value);

str.replace(/pattern/, toStr);


ex:
var filename = '20080919114201';
var requestTime = filename.replace(/^(....)(..)(..)(..)(..)(..)$/, "$1-$2-$3 $4:$5:$6");
--> 결과
2008-09-19 11:42:01


  • match()
var str="Hello world!";
document.write(str.match("world") + "<br />");
document.write(str.match("World") + "<br />");
document.write(str.match("worlld") + "<br />");
document.write(str.match("world!"));
--> 결과
world
null
null
world! 

  • test()
RegExpObject.test(string)
Valid XHTML 1.0! Valid CSS! powered by MoniWiki
last modified 2009-10-21 01:38:05
Processing time 0.0064 sec