Skip to content

Instantly share code, notes, and snippets.

@aarti
Created February 26, 2014 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aarti/9233441 to your computer and use it in GitHub Desktop.
Save aarti/9233441 to your computer and use it in GitHub Desktop.
Regexp using negative lookahead and negative look behind assertions
irb(main):040:0> testcases
=> ["hello world", "'hello world", "'hello' world", "hello' world"]
irb(main):041:0> testcases.each { |i| puts /(?<!')hello(?!')/.match(i) }
hello
=> ["hello world", "'hello world", "'hello' world", "hello' world"]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment