Skip to content

Instantly share code, notes, and snippets.

View mroffice's full-sized avatar

Euan Callus mroffice

  • Phonesmart Ltd
  • Glasgow
View GitHub Profile
@mroffice
mroffice / Reg Exp.md
Last active February 15, 2016 13:23
An overview of Regular Expressions, with examples

Flags

Flag Description Truthy Example Falsey Example
^ Matches the beginning of input /^b/.test("bananas") /^ananas/.test("bananas")
\ In effect reverses the 'specialness' of a letter /\bb/.test("bananas") /b\b/.test("bananas")
$ Matches the end of input /anas$/.test("bananas") /banan$/.test("bananas")
* Matches the preceeding expression 0 or more times /bananas*/.test("banana") or /bananas*/.test("bananasssssssss") /(bananas)*/.test("monkey")
+ Matches the preceeding expression 1 or more times /bananas+/.test("bananasss") /bananas+/.test("banana")
? Matches the preceeding character 0 or 1 time /ba?na?na?/.exec("banana") // => ["banana"] or /ba?na?na?/.exec("bnn") // => ["bnn"] /ba?na?na?/.exec("bana") // => null