create regular expression code example

Example 1: regex for strings with specific letters javascript

let re = /ab+c/;

Example 2: regular expression javascript

// Tests website Regular Expression against document.location (current page url)
if (/^https\:\/\/example\.com\/$/.exec(document.location)){
	console.log("Look mam, I can regex!");
}

Example 3: regex examples

[abc]            matches a string that has either an a or a b or a c -> is the same as a|b|c -> Try it![a-c]            same as previous[a-fA-F0-9]      a string that represents a single hexadecimal digit, case insensitively -> Try it![0-9]%           a string that has a character from 0 to 9 before a % sign[^a-zA-Z]        a string that has not a letter from a to z or from A to Z. In this case the ^ is used as negation of the expression -> Try it!

Tags:

R Example