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 |
NewerOlder