JavaScript RegExp – toString
说明
toString 方法返回一个正则表达式的字符串表示形式,即一个正则表达式字面值。
语法
syntax 是如下形式的:-
RegExpObject.toString();
返回值
返回正则表达式的字符串表示形式。
例子
<html>
<head>
<title>JavaScript RegExp toString Method</title>
</head>
<body>
<script type = "text/javascript">
var str = "Javascript is an interesting scripting language";
var re = new RegExp( "script", "g" );
var result = re.toString(str);
document.write("Test 1 - returned value : " + result);
re = new RegExp( "/", "g" );
var result = re.toString(str);
document.write("<br />Test 2 - returned value : " + result);
</script>
</body>
</html>
输出
Test 1 - returned value : /script/g
Test 2 - returned value : /\//g