Tutorial Gateway

  • C
  • C#
  • Java
  • Python
  • SQL
  • MySQL
  • Js
  • BI Tools
    • Informatica
    • Talend
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • R Tutorial
    • Alteryx
    • QlikView
  • More
    • C Programs
    • C++ Programs
    • Go Programs
    • Python Programs
    • Java Programs

JavaScript Match

by suresh

The JavaScript Match function is one of the String Functions. This JavaScript string match function is used to search for a specified string and return the array of matched substrings. The syntax of the string match function in JavaScript is

String_Object.match(RegExp)
  • String_Object: String to perform a search. JS Match function check for a portion of a string present in this String_Object
  • RegExp: Valid string or Regular expression you want to match. If the specified substring is not in the string_object, the Match function will return NULL

JavaScript Match Example

The following set of examples will help you understand the string match function.

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript Match </title>
</head>
<body>
    <h1> JavaScript Match </h1>
<script>
    var Str1 = "We are ABC working at abc company since Abc years";
    var Str2 = "We are abc working at abc company since Abc years";
    var Str3 = Str2.match("abc");
    var Str4 = Str2.match(/abc/g);
    var Str5 = Str1.match("abc");
    var Str6 = Str1.match(/abc/gi);
    var Str7 = Str1.match("JavaScript");
 
    document.write(Str3 + "<br \>");
    document.write(Str4 + "<br \>");
    document.write(Str5 + "<br \>");
    document.write(Str6 + "<br \>");
    document.write(Str7);
</script>
</body>
</html>
JavaScript MATCH Function

Following statement will search for ‘abc’ and return it. As you can see, ‘abc’ substring repeated thrice in Str2, but the Match String Function is returning the first occurrence

var Str3 = Str2.match("abc");

Next, we used a regular expression to search for ‘abc’ substring globally. So, JavaScript match function returns every occurrence of ‘abc’ to output

var Str4 = Str2.match(/abc/g);

From the above statement, you can observe that the term abc repeated many times. However, the JS Match function considers the string “ABC” is different from “abc” and “Abc”. Now, let us use the i regular expression along with string (i will perform the case insensitive string search.)

var Str6 = Str1.match(/abc/gi);

Finally, we used a non-existing item inside the string match function. As we said before, JavaScript returns NULL as output

var Str7 = Str1.match("JavaScript");

Placed Under: JavaScript

  • SQL DML, DDL, DCL & TCL Cmds
  • SQL NOT EXISTS Operator
  • SQL UPDATE from SELECT
  • SQL AFTER UPDATE Triggers
  • SQL Get Column Names in Table
  • SQL IF ELSE
  • SQL ACID Properties
  • SQL FOR XML PATH
  • Java Two Dimensional Array
  • Java Perfect Number Program
  • Java Count Digits in a Number
  • C Compare Two Strings Program
  • C Print Prime Numbers 1 to 100
  • C program to Reverse a String
  • C Palindrome Number Program
  • C Program for Palindrome String
  • C Remove Duplicate String Chars
  • C Square of a Number Program
  • C Sum and Average of N Number
  • Python Fibonacci Series program
  • Python Area Of Circle Program
  • Python Prime Numbers 1 to 100
  • Python Program for Leap Year
  • Tableau Rank Calculation
  • Tableau Google Maps usage
  • Power BI Format Dates
  • Power BI Top 10 Filters
  • Power BI – Create Hierarchy
  • Power BI DAX Math Functions
  • Learn SSIS in 28 Days
  • SSIS Transformations
  • SSIS Incremental Load
  • SSRS Drill Through Reports
  • SSRS Drill Down Reports
  • R Programming Tutorial

Copyright © 2021 · All Rights Reserved by Suresh

About Us | Contact Us | Privacy Policy