Skip to content
Related Articles

Related Articles

JavaScript | RegExp \f Metacharacter
  • Last Updated : 16 Oct, 2019

The RegExp \f Metacharacter in JavaScript is used to find the form feed character (form feed is a page-breaking ASCII control character). If it is found it returns the position else it returns -1.

Syntax:

/\f/ 

or

new RegExp("\\f")

Example 1: This example searches for the form feed character in the string.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript RegExp \f Metacharacter
    </title>
</head>
  
<body style="text-align:center">
      
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
      
    <h2>RegExp \f Metacharacter</h2>
      
    <p>Input String: GeeksforGeeks@_123_$</p>
      
    <button onclick="geek()">
        Click it!
    </button>
      
    <p id="app"></p>
      
    <script>
        function geek() {
            var str1 = "GeeksforGeeks@_123_$";
            var regex4 = /\f/;
            var match4 = str1.search(regex4);
            if(match4 == -1) {         
                document.getElementById("app").innerHTML
                = "No form feed character present. ";
            } else {
                document.getElementById("app").innerHTML
                = "Index of form feed character: " + match4;
            }
        }
    </script>
</body>
  
</html>                    

Output:
Before Clicking the button:
backf
After Clicking the button:
backf



Example 2: This example searches the position of the form feed character in the string.




<!DOCTYPE html>
<html>
  
<head>
    <title>
        JavaScript RegExp \f Metacharacter
    </title>
</head>
  
<body style="text-align:center">
      
    <h1 style="color:green">
        GeeksforGeeks
    </h1>
      
    <h2>RegExp \f Metacharacter</h2>
      
    <p>String: 123ge\feky456</p>
      
    <button onclick="geek()">
        Click it!
    </button>
      
    <p id="app"></p>
      
    <script>
        function geek() {
            var str1 = "123ge\feky456";
            var regex4 = new RegExp("\\f");         
            var match4 = str1.search(regex4);
            document.getElementById("app").innerHTML = 
            " Index of form feed character: " + match4;
        }
    </script>
</body>
  
</html>                    

Output:
Before Clicking the button:
backf
After Clicking the button:
backf

Supported Browsers: The browsers supported by RegExp \f Metacharacter are listed below:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer
My Personal Notes arrow_drop_up
Recommended Articles
Page :