Skip to content

Instantly share code, notes, and snippets.

@rauschma
Last active April 16, 2018 19:43
Show Gist options
  • Save rauschma/7a2977abbe5fc97ec03b to your computer and use it in GitHub Desktop.
Save rauschma/7a2977abbe5fc97ec03b to your computer and use it in GitHub Desktop.
Regular expressions in ES6

Methods of regular expressions:

Flags Start matching Anchored to Result if match No match re.lastIndex
exec() 0 Match object null unchanged
/g re.lastIndex Match object null index after match
/y re.lastIndex re.lastIndex Match object null index after match
/gy re.lastIndex re.lastIndex Match object null index after match
test() (Any) (like exec()) (like exec()) true false (like exec())

Methods of strings:

Flags Start matching Anchored to Result if match No match re.lastIndex
match() 0 Match object null unchanged
/y re.lastIndex re.lastIndex Match object null index after match
/g After prev. match (loop) Array with matches null 0
/gy After prev. match (loop) After prev. match Array with matches null 0
search() 0 Index of match -1 unchanged
/y 0 0 Index of match -1 unchanged
replace() 0 First match replaced No repl. unchanged
/y 0 0 First match replaced No repl. unchanged
/g After prev. match (loop) All matches replaced No repl. unchanged
/gy After prev. match (loop) After prev. match All matches replaced No repl. unchanged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment