JavaScript regular expressions: “\w”
character
[this page | pdf | back links]
A JavaScript
regular expression takes the form: /pattern/modifiers
The character sequence \w
in a regular expression has a special meaning, namely a word character.
EXAMPLE:
HTML USED IN THIS EXAMPLE:
<!DOCTYPE html>
<html> <!-- Copyright (c) Nematrian Limited 2018 -->
<head>
<style>
table,th,tr,td {border: 1px solid black; border-collapse: collapse;}
</style>
</head>
<body>
<table>
<tr>
<th>Example</th>
<th>Resulting value of <code>x</code></th>
</tr>
<tr>
<td><code id="Example"></code></td>
<td><code id="Result"></code></td>
</tr>
</table>
<script>
var str = "Hello 1234";
document.getElementById("Example").innerHTML =
'var str = "Hello 1234";<br>' +
'var x = str.replace(/\\w/gi,"*");';
document.getElementById("Result").innerHTML
= str.replace(/\w/gi,"*");
</script>
</body>
</html>
|
NAVIGATION LINKS
Contents | Prev | Next | JavaScript Regular Expressions