Skip to content

Instantly share code, notes, and snippets.

@judofyr
Created August 11, 2009 17:39
Show Gist options
  • Save judofyr/165986 to your computer and use it in GitHub Desktop.
Save judofyr/165986 to your computer and use it in GitHub Desktop.
REGEXP_PAIRS = Hash[*%w[{ } ( ) [ ] < >]]
REGEXP_PAIRS.default_proc = proc { |h, k| k }
def on_regexp_beg(content)
@regexp_stack << content
end
def on_regexp_end(content)
start = @regexp_stack.pop[-1]
stop = Regexp.escape(REGEXP_PAIRS[start])
content =~ /#{stop}([^#{stop}])$/
extra, options = $`, $1
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment