I'm trying to optimize one of my .NET app's regular expression.
Regex: (?<!WordA\s(?:WordB\s)?)(WordB\s)?WordC
Logic:
- Find matching WordC
- Join WordB to match (if present right before WordC)
- Don't match anything if WordC (even if preceeded by WordB) is preceeded by WordA
Should Match:
- WordC
- WordB WordC
Should Not Match:
- WordA WordC
- WordA WordB WordC
The expression works but as you can see the WordB is present two times in the expression so I'm trying to remove one of them to get better performance.
Note: "Words" are in fact complex expressions.
Is there any way?