Regex

Matching one string

"aaaa".match(/[a]/)

Result:

["a"]

Matching multiple substrings

"a a123a a123a b123b c".match(/a(123)a/g)

Result:

["a123", "a123"]

Note the trailing /g

  • You cannot select individual groups while using g

Last updated