Skip to content

Instantly share code, notes, and snippets.

@swalke16
Created March 17, 2010 17:52
Show Gist options
  • Save swalke16/335509 to your computer and use it in GitHub Desktop.
Save swalke16/335509 to your computer and use it in GitHub Desktop.
Regex to match the following (JavaScript):
before
before {each:1,shared:1}
after
after {each:1,shared:1}
The patterns should match at the beginning of a line, and ends at the end of a line. The before/after part should be captured into backreference $1 and the {} part should be captured into backreference $2 (if it exists).
Here's what I've got so far, I think it's close, the only real problem I know of is that in the simple before/after case it's capturing the before/after into backreference $3 instead of $1.
^ *(before|after) *?({.+?})(?= |$)|(before|after)(?= |$)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment