I’m doing some form of data visualization learning for 180 days because I need to #JFDI.

See post explaining how and why I’m doing this.

Code Learning:

Finding Strings using RegEx

var str = "how much wood would a woodchuck chuck"

var regex = "/wood/";

if (regex.test(str)) {

                console.log("We found 'wood' in the string!");

}

=> "We found 'wood' in the string!"

To see actual matches

var matches = str.match(regex);

console.log(matches)

=> ["wood"]

Find all instances of wood

regex = /wood/g;

console.log(str.match(regex));

=> ["wood", "wood", "wood", "wood"]

Extend regular expression match expression that matches everything that starts with wood followed by – or more characters

regex = /wood.*?\b/g;

console.log(str.match(regex));

=> ["wood"]


Posted in , , ,

Leave a Reply