JavaScript RegExp v Metacharacter

In JavaScript, the regular expression "\v" is used to identify the vertical tab character within a given input string. When the vertical tab character is found, the search method indicates its position, while a value of "-1" is returned if it is not present. This Metacharacter can be utilized for testing, searching, and matching specific strings as needed.

Syntax

The syntax displays the vertical tab character within the input string.

Example

new RegExp("\\v")

Supported Browsers

The RegExp \v Metacharacter supports the following browsers supported using the javascript function:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer
  • Examples

These instances demonstrate how to search for, match, test, and execute vertical tab characters using the "\v" regex metacharacter in JavaScript.

Example 1

The provided example demonstrates the use of the vertical tab character metacharacter in a JavaScript regex. The test method returns a boolean value indicating whether the character is present in the string.

Example

<!DOCTYPE html>
<html>
<head>
    <title>
        JavaScript RegExp \v (vertical tab character) Metacharacter
    </title>
    <style>
        #demo1 {
            background-color: orange;
            border: 1px solid black;
            width: 280px;
        }
    </style>
</head>
<body>
    <div id="demo1">
        <h3>
            JavaScript RegExp \v Metacharacter
        </h3>
        <h4> We can use the validation for the vertical tab character values position 
                 in the input string.
        </h4>
        <div id="regex_information"></div>
        <!-- Click the button to get regex output -->
        <button onclick="display();"> Click Here! </button>
    </div>
    <script>
        function display() {
            //use vertical tab characters Metacharacter of the regex
            let vertical_pattern = /\v/;
            var vertical_t1 = vertical_pattern.test('\v992JavaScript');
            var vertical_t2 = vertical_pattern.test('Hii~.\v=@Err');
            var vertical_t3 = vertical_pattern.test('%!@!#$%');
            // Get the availability shows the Boolean value of the vertical tab character
            var ele = document.getElementById("regex_information");
            ele.innerHTML = "\v992JavaScript   : " + vertical_t1 + "<br> Hii~.\v=@Err : " + vertical_t2 +
                " <br> %!@!#$% : " + vertical_t3
        }
    </script>
</body>
</html>

Output

The output displays the vertical tab character present in the string.

Example 2

In the upcoming illustration, the regex in JavaScript is demonstrated to determine the position of the vertical tab character metacharacter. In cases where the vertical tab character value is not found, the output will display "-1".

Example

<!DOCTYPE html>
<html>
<head>
    <title>
        JavaScript RegExp \v (vertical tab character) Metacharacter
    </title>
    <style>
        #demo1 {
            background-color: orange;
            border: 1px solid black;
            width: 280px;
        }
    </style>
</head>

<body>
    <div id="demo1">
        <h3>
            JavaScript RegExp \v Metacharacter
        </h3>
        <h4> We can use the validation for the vertical tab character values position 
                 in the input string.
        </h4>
        <div id="regex_information"></div>
        <!-- Click the button to get regex output -->
        <button onclick="display();"> Click Here! </button>
    </div>
    <script>
        function display() {
            //use vertical tab characters Metacharacter of the regex
            let vertical_pattern = /\v/;
            var input_val1 = 'javatoint website\v';
            var input_val2 = 'Hii Coder';
            var input_val3 = '\v%!@!#$%0';
            //Use the search method to find the position of the Metacharacter
            var vertical_t1 = input_val1.search(vertical_pattern);
            var vertical_t2 = input_val2.search(vertical_pattern);
            var vertical_t3 = input_val3.search(vertical_pattern);
            // Get the index position of the value as an output
            var ele = document.getElementById("regex_information");
            ele.innerHTML = "javatoint website\v : " + vertical_t1 + "<br> 
Hii Coder : " + vertical_t2 +
                " <br> \v%!@!#$% : " + vertical_t3;
        }
    </script>
</body>
</html>

Output

The output indicates the index of the vertical tab character within the string.

Example 3

In the JavaScript regex, the example below illustrates the position of the metacharacter for the vertical tab character. In case the vertical tab value is not available, the output will display as "null".

Example

<!DOCTYPE html>
<html>
<head>
    <title>
        JavaScript RegExp \v (vertical tab character) Metacharacter
    </title>
    <style>
        #demo1 {
            background-color: orange;
            border: 1px solid black;
            width: 280px;
        }
    </style>
</head>
<body>
    <div id="demo1">
        <h3>
            JavaScript RegExp \v Metacharacter
        </h3>
        <h4> We can use the validation for the vertical tab character values position in the input string.
        </h4>
        <div id="regex_information"></div>
        <!-- Click the button to get regex output -->
        <button onclick="display();"> Click Here! </button>
    </div>
    <script>
        function display() {
            //use vertical tab characters Metacharacter of the regex
            let vertical_pattern = /\v/;
            var input_val1 = 'javatoint website\v';
            var input_val2 = '!!#HiiErr';
            var input_val3 = '\v%!@!#$%0';
            var vertical_t1 = input_val1.match(vertical_pattern);
            var vertical_t2 = input_val2.match(vertical_pattern);
            var vertical_t3 = input_val3.match(vertical_pattern);
            // the match regex pattern and shows array value as an output
            var ele = document.getElementById("regex_information");
            ele.innerHTML = "javatoint website\v : " + vertical_t1 + 
           "<br> !!#HiiErr : " + vertical_t2 +  " <br> \v%!@!#$% : " + vertical_t3;
        }
    </script>
</body>
</html>

Output

The output indicates the index of the vertical tab character within the string.

Example 4

In the code snippet below, the position of the vertical tab character metacharacter in a regular expression in JavaScript is demonstrated. When the vertical tab value is not present, the output will display as "null".

Example

<!DOCTYPE html>
<html>
<head>
    <title>
        JavaScript RegExp \v (vertical tab character) Metacharacter
    </title>
    <style>
        #demo1 {
            background-color: orange;
            border: 1px solid black;
            width: 280px;
        }
    </style>
</head>

<body>
    <div id="demo1">
        <h3>
            JavaScript RegExp \v Metacharacter
        </h3>
        <h4> We can use the validation for the vertical tab character. We can replace the value of the Metacharacter
            using JavaScript regex. </h4>
        <div id="regex_information"></div>
        <button onclick="display();"> Click Here!</button>
    </div>
    <script>
        function display() {
            //use vertical tab characters Metacharacter of the regex
            let vertical_pattern = /\v/;
            var input_val1 = 'javatoint website\v';
            var input_val2 = '!!#HiiErr';
            var input_val3 = '\v%!@!#$%0';
            var replace_input = '7777';
            var vertical_t1 = input_val1.replace(vertical_pattern, replace_input);
            var vertical_t2 = input_val2.replace(vertical_pattern, replace_input);
            var vertical_t3 = input_val3.replace(vertical_pattern, replace_input);
        // Get the output of the replace value of the vertical tab characters
        var ele = document.getElementById("regex_information");
        ele.innerHTML = "javatoint website\v : " + vertical_t1 + "<br> !!#HiiErr : " + vertical_t2 +
            " <br> \v%!@!#$% : " + vertical_t3;
        }
    </script>
</body>
</html>

Output

The output displays the substituted value of the vertical tab character within the string.

Conclusion

Regular expressions are utilized in JavaScript to identify vertical tab characters within data using built-in methods. This straightforward meta-character aids in validating user-entered information.

Input Required

This code uses input(). Please provide values below: