Skip to content

Instantly share code, notes, and snippets.

@aarti
Created February 26, 2014 16:51
Show Gist options
  • Select an option

  • Save aarti/9233441 to your computer and use it in GitHub Desktop.

Select an option

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