InDesign GREP: Unexpected behavior with OR operator and anchors
Problem Description
I've discovered that InDesign GREP behaves differently from standard regex engines when using the OR operator (|) combined with anchors (^ and $). This seems to be an undocumented behavior that differs significantly from what most regex documentation would suggest.
Test Cases
Test Case 1: ^ab|c
Text: ab ac bc Expected (standard regex): Matches "ab" at line start AND "c" anywhere Actual InDesign result: Only matches "ab" at line start
Test Case 2: ^a|bc
Text: ab ac bc Expected (standard regex): Matches "a" at line start AND "bc" anywhere Actual InDesign result: Only matches "a" at line start
Test Case 3: (^a)|bc
Text: ab ac bc Expected (standard regex): Matches "a" at line start AND "bc" anywhere Actual InDesign result: Still only matches "a" at line start
Test Case 4: (a$)|bc
Text: ab ac bca Expected (standard regex): Matches "a" at line end AND "bc" anywhere Actual InDesign result: Only matches "bc" (ignores the anchor completely)
Observations
- InDesign GREP appears to interpret ^ab|c as ^(ab|c) instead of (^ab)|c
- Even explicit grouping (^a)|bc doesn't work as expected
- The $ anchor behaves inconsistently - sometimes ignored entirely
- This behavior is not documented in Adobe's official documentation
- Peter Kahrel's "GREP in InDesign" book notably omits any discussion of the OR operator
Questions
- Is this a known bug or intentional design choice?
- Are there any workarounds to achieve standard OR behavior with anchors?
- Why does the $ anchor behave differently from ^ in OR expressions?
- Has Adobe ever officially addressed this inconsistency?
