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

0
()

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 .

str.match(regexp);

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

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

Result

["$8", "$11"]

JavaScript String – match() Method

index.html



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


Result

Unit 3.4.5.1,Unit 3.4.5.1,.1

JavaScript String match()

A global seach for “date”:

let text = "The rdate in SPdate stays mdately in the pldate";
text.match(/date/g);

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

Download

I hope you get an idea about javascript match.
I would like to have feedback on my infinityknow.com.
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!