The following code removes the brackets and a dash from the string variable.
I am interested why there are \ in front of each bracket in the regular expression regexp?
The code work fine if regexp would be /()-/g;
So why then / is necessary? I would appreciate a lot with someone could explain.
Thank you very much.
<html>
<head>
<title>Regular Expressions</title>
<script type="text/javascript">
var string="(304)434-5454";
regexp=/[\(\)-]/g;
document.write(string.replace(regexp, ""));
</script>
</head>
<body>
</body>
</html>
I am interested why there are \ in front of each bracket in the regular expression regexp?
The code work fine if regexp would be /()-/g;
So why then / is necessary? I would appreciate a lot with someone could explain.
Thank you very much.
<html>
<head>
<title>Regular Expressions</title>
<script type="text/javascript">
var string="(304)434-5454";
regexp=/[\(\)-]/g;
document.write(string.replace(regexp, ""));
</script>
</head>
<body>
</body>
</html>
Comment