<html><head><title>JavaScript RegExp toSource Method</title></head><body><scripttype="text/javascript">var str ="Javascript is an interesting scripting language";var re =newRegExp("script","g");var result = re.toSource(str);
document.write("Test 1 - returned value : "+ result);
re =newRegExp("/","g");var result = re.toSource(str);
document.write("<br/>Test 2 - returned value : "+ result);</script></body></html>
HTML
输出
Test1- returned value :/script/g
Test2- returned value :/\//g