RegEx Cheater
regular expressions cheat sheet
by trentHarlem
HTML
<!--
Anchors
Qualifiers
-->
JavaScript
// identifies all white space
let spaces = /\s+/g
// identifies white space at beginning and end
let bookendSpaces = /^\s+|\s+$/g
// identifies all letter/number characters
let letters = /\w+/g
// all vowels regardless of case
let vowels = /[a,e,i,o,u]/gi
// identifies all letter/number characters
//let notLetter = /\W+/g
let notLetter = /[^\w+]/g
//Negation. Anything that doesn't contain 'foo'
let negate = /^(?!.*foo).+$/
// identifies all beginnings and endings)
let wordBoundry = /\b/g
// all white space and non-letter characters
let nonLetters = /\W/g
// find quotes
//let highlighter = /('|").+?\1/g
let highlighter = /('|"|(\'|\")).+?\1/g
//let highlighter = /('|")(\\?.).*?\1/g
// all letter groups (words) with 4 or more char in a row
let longerThan = /\w{4,}/g
// 6+ letter password with at least:
// one number, one letter and one symbol
let password = /^(?=.*\d)(?=.*[a-z])(?=[\W_]).{6,}$/i
let lookBehind = /(?<= )/g
let hex = /(#[0-9a-f]+)/gi
let numbers = /^[-+.$]?\d*\.?\d*/g
let dates = /^\d{4}-(0\d|1[0-2])-([0-2]\d|3[01])$/g;
let first = /^We/g;
let letter
let firstLetter = /^${letter}/g
//--------------- FUNCTIONS
let sentence = 'The brown fox jumped over lazy foo river-dogs.'
let sentenceSpace = 'The brown fox jumped over foo lazy river-dogs. \"He said \'Boo!\'\" "He said Boo!"'
let doubleSpace = 'The brown fox jumped over foo lazy river.'
let we = 'We the people...'
let hexCodes = '#000 red #131313 black #a0f5c9 green #fff #F0F'
let numberList = '-1, .05, +1003, 3.1415926535, 42., $22, $1.00'
let numberArray = [-1, .05, +1003, 3.1415926535, 42., 'sentence']
function wordCount(string) {
// groups of letters (words) that match the regex will by default be separated by characters that do NOT match (.,- etc)
return string.match(letters).length
//return string.match(wordBoundry).length/2
//return string.match(nonLetters).length
}
/* function startsWith(string,letter) {
// first word that starts...