Skip to content

Instantly share code, notes, and snippets.

@colinux
Created February 10, 2012 23:13
Show Gist options
  • Save colinux/1793893 to your computer and use it in GitHub Desktop.
Save colinux/1793893 to your computer and use it in GitHub Desktop.
Regex to match a string which does not contain another string or pattern
  1. Matches strings not containing foo. (fast)

    /(?:[^f]+|f(?!oo))*/

  2. Matches strings not containing PATTERN (slow). s modifier is required if the . can match a new line.

    /(?:(?!PATTERN).)*/s

source

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