Writing a simple function to extract matched strings using Regex in Javascript Today i want to show how to extract string data using Regular Expression in Javascript. A regular expression is an object that describes a pattern of characters. Syntax for javascript : / pattern / modifiers ; First we can create a simple function that will process the string extraction. example of string input will be something like this <p>This is just a simple example input string</p> ( [message] => "Hello", [desc] => "its a handshake hello!" ) <p>The purpose is to extract message and desc pattern matching</p> Simple function that will process the string extraction function extract(stringInput) { var regexp = /\[(message|desc)\](.*)/gm; var arr = []; while (result = regexp.exec(stringInput)) { arr.push(result[0]); } return arr; } The ' extract ' function will look for a pattern on anything that has opening bracket with the matching ...
This is a blog that shares tips on Coding, Website, E-Commerce, Windows, Linux and IT related infos.