JavaScript Regular Expressions The exec() method tests for a match in a string: let text = "Hello world!"; // look for "Hello" let result1 = /Hello/.exec(text); // look for "W3Schools" let result2 = /W3Schools/.exec(text); document.getElementBy...
<!DOCTYPE html> JavaScript Regular Expressions The constructor property returns the function that created the RegExp prototype: let pattern = /Hello World/g; let text = pattern.constructor; document.getElementById("demo").innerHTML = text; ...
JavaScript Regular Expressions A global search for any character from uppercase "A" to lowercase "e": let text = "I Scream For Ice Cream, is that OK?!"; let pattern = /[A-e]/g; let result = text.match(pattern); document.getElementById("demo").innerHTML...
JavaScript Regular Expressions Do a global, multiline search for "is" at the end of each line in a string. let text = `Is this all there is` let pattern = /is$/gm; let result = text.match(pattern); document.getElementById("demo").innerHTML = result; ...
JavaScript Regular Expressions Do a global, case-insensitive, multiline search for "is" at the beginning of each line in a string. let text = `Is this all there is` let pattern = /^is/gmi; let result = text.match(pattern); document.getElementById("demo").inne...
JavaScript Regular Expressions A global search for the characters "i" and "s" in a string: let text = "Do you know if this is all there is?"; let pattern = /[is]/gi; let result = text.match(pattern); document.getElementById("demo").innerHTML = result...
JavaScript Regular Expressions A global search for a "1", followed by zero or more "0" characters: let text = "1, 100 or 1000?"; let pattern = /10*/g; let result = text.match(pattern); document.getElementById("demo").innerHTML = result; ...
JavaScript Regular Expressions Do a global search for the character "h" in a string: let text = "Is this all there is?"; let result = text.match(/[h]/g); document.getElementById("demo").innerHTML = result; ...
<!DOCTYPE html> JavaScript Regular Expressions The d modifier Match all that starts or ends with aa or bb: let text = "aaaabb"; let result = text.match(/(aa)(bb)/d); document.getElementById("demo").innerHTML = result; ...
JavaScript Regular Expressions Do a global search for whitespace characters in a string: let text = "Is this all there is?"; let result = text.match(/\s/g); document.getElementById("demo").innerHTML = result; ...