JavaScript \xxx Metacharacter | Find Character using Octal Number

The JavaScript \xxx metacharacter is used when we need to match a character using its octal number (in the form xxx), while working with JavaScript regular expression. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="xyz"></p>

   <script>
      let myString = "JavaScript is Fun.";
      let pattern = /\165/;
      document.getElementById("xyz").innerHTML = myString.search(pattern);
   </script>
   
</body>
</html>
Output

Since the octal value 165 refers to u. And the index of u in the string is 15. Therefore the program has produced 15 as output.

Note: The search() method is used to search a substring (value) in a string using regular expression.

JavaScript Online Test


« Previous Tutorial Next Tutorial »