Skip to content

Instantly share code, notes, and snippets.

@aurbano
Last active October 27, 2016 14:11
Show Gist options
  • Save aurbano/096ae9d24c498295ddf42de229f38cab to your computer and use it in GitHub Desktop.
Save aurbano/096ae9d24c498295ddf42de229f38cab to your computer and use it in GitHub Desktop.
Match a word preceded by specific words, but not others, and with optional appendixes

Regex

((pre1)|pre2)?(?(1)\s)(?<!notallowed )main word(?(2)-appendix1)

This will match

pre1 main word-appendix1 pre2 main word main word

It will not match

notallowed main word

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