Regular Expressions 101

Community Patterns

conditional lookahead (IF (pat1) or (pat2) THEN match (pat1) and/or (pat2) box

0

Regular Expression
Python

r"
(?i)(?=(((\()?(red|gold|silver|king)( pack)?(\))?)|((70|83|84|100|120)(s|'s)?)))((((\()?(red|gold|silver|king)( pack)?(\))? )?((70|83|84|100|120)(s|'s)? )?)(\bbox\b))
"
gm

Description

Python does not support conditionals using lookaround, even though Python does support lookaround outside conditionals. (?(?=regex) then|else) is illegal in python (?=regex)then|(?!regex)else - this works. madness

details in the test strings

Submitted by PeteC - 2 years ago