Skip to content

Instantly share code, notes, and snippets.

@vainikkaj
Created April 17, 2016 20:29
Show Gist options
  • Save vainikkaj/3581872b7b2b1f6a1be0d97d75bb7f4d to your computer and use it in GitHub Desktop.
Save vainikkaj/3581872b7b2b1f6a1be0d97d75bb7f4d to your computer and use it in GitHub Desktop.
Different regular expression lookahead exaxmples
assert 'hello world' =~ /\w{5}(?<=hello) world/
assert 'hello world' ==~ /hello (?=world)\w{5}/
assert 'x9' ==~ /.(?<=x)9/
assert 'x9' ==~ /x(?=9)./
assert 'x9' ==~ /\w(?<=x)9/
assert 'x9' ==~ /x(?=9)\d/
assert 'x9' ==~ /\w\d/
assert 'x9' ==~ /x\d/
assert 'x9' ==~ /x9/
assert 'x49' ==~ /x(?=49)..(?<=49)/
assert 'x4' ==~ /x(?=4).(?<=4)/
assert 'blah <h2>hi</h2> blah'.find('(?<=<h2>).+(?=</h2>)') == 'hi'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment