Skip to content

Instantly share code, notes, and snippets.

@sajadtorkamani
Last active April 29, 2017 11:14
Show Gist options
  • Save sajadtorkamani/83fbeabeb1e268e1bc22e3be1d7421db to your computer and use it in GitHub Desktop.
Save sajadtorkamani/83fbeabeb1e268e1bc22e3be1d7421db to your computer and use it in GitHub Desktop.
AND in Regex

Called a look-ahead expression, we can use this to match multiple expressions:

Syntax:

(?=match this expression)(?=match this too)(?=oh, and this)

Example - match string containing the words 'ruby' and 'rails' (regardless of order of occurence):

"ruby rails".match(/(?=.*ruby)(?=.*rails)/)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment