Skip to content

Instantly share code, notes, and snippets.

@scshepard
Forked from rauschma/regexp_es6.md
Last active August 29, 2015 14:25
Show Gist options
  • Save scshepard/4d2d2bccb5cee6d8d144 to your computer and use it in GitHub Desktop.
Save scshepard/4d2d2bccb5cee6d8d144 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