Vue.Js String Match


We can use native JavaScript string match function to search a string against regular expression. Here in this tutorial, we are going to explain how you can use string match method in VueJs. You can also use our online editor to edit and run the code online.


String Match Method Vue.Js JavaScript Example

You can use JavaScript match() method simply as below-

Example:

<!DOCTYPE html>
<html>
<head>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.13/vue.js"></script>
</head>
<body>
<div id="app">
	{{result}}
</div>
<script>
 new Vue({
el: '#app',
  
  data: { 
	  str:"learn - You can find more tutorials to learn everything here.",
	  result: ''
  },
  
   methods:{
    myFunction: function () {
      var v = this;
	  var r = v.str.match(/learn/g);
	  v.result = r;// return match array
    }
	},
  mounted () {
  this.myFunction();
}

});
</script>        
</body>
</html>

Try it »

The above example will return the array of objects against the match.

Output of above example-

Vue.Js String Match Javascript Example

Advertisements

Add Comment

📖 Read More