javascript match – JavaScript String match() Method with Regular expressions


javascript match : Use regex.test() Check whether a string matches a regex in JS get the matches when matching a string against a regular expression.

Free Live Chat for Any Issue

javascript match & Regex Match Example

Introduction to the JavaScript String match() method – The match() method returns the matches in an array. The method str.match(regexp) finds matches for regexp in the string str .


Using the match() method with the expression that has the global flag

let str = "Amount: $8–$11";
let result = str.match(/\$\d+/g);


["$8", "$11"]

JavaScript String – match() Method


<script type = "text/javascript">
         var user_input = "For more details, see Unit";
         var dt = /(unit \d+(\.\d)*)/i;
         var rsdata = user_input.match( dt );         
         document.write(rsdata ); 



JavaScript String match()

A global seach for “date”:

let text = "The rdate in SPdate stays mdately in the pldate";

Don’t Miss : Email validation in JavaScript on button click


I hope you get an idea about javascript match.
I would like to have feedback on my
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Read Also:  JavaScript JSON Encoder and Decoder Example

How useful was this post?

Click on a star to rate it!