You are reading a single comment by @gbj_tester and its replies. Click here to read the full conversation.
  • Anybody good at regex? If I have

    1. (bea?)trix(ie?)

    How do I specify that if there is one instance of Bea there must be zero instances of ie and vice versa?

  • If you don't actually need a regular expression, eg you're using PCRE or similar, then you want a negative lookahead:
    (beatrix(?!ie)|(?!bea)trixie)

    It is possible to do it with standard regular expressions (since every regular language can be negated), but it's much more painful.

    Edit: for completeness, here's what that would look like:

    1. (?:(?:(?:[^b]|b(?:b|eb)*?(?:[^be]|e[^ab]))*?(?:b(?:b|eb)*e?)??(trixie))|(?:(beatrix)(?:(?:[^i]|i+[^ei])*?i*?)))

    (?: ) is a non-capturing group, *? and ?? are lazy (rather than greedy) matching, negations constructed using this tool http://www.formauri.es/personal/pgimeno/misc/non-match-regex/

    As you can see, it gets messy fast.

About

Avatar for gbj_tester @gbj_tester started