When using positive lookbehind (?<= ... )
such as this...
(?<=open|enter).+
... to get a match on efterything following the words "open" or "enter", I found a small problem with the grep implementation in InDesign (or so I think).
Requiring that either word exists, I find no other solution than to set up two different grep expressions, which is acceptable, but in my eyes not very good:
My example is simplified here.
It seems that the two "alternate" words, need to be the same length, to get a match. And before sending this as a question, I found that Jongware had this in his GREP help:
(?<=text) (positive lookbehind) | fixed length |
(?<!text) (negative lookbehind) | fixed length |
From http://www.jongware.com/idgrephelp.html
So adding a space after "open ", would get me the right result, since both words are now of the same length:
(?<=open |enter).+
But in my real world scenario that's not possible (since the words are of completely different lengths).
*** Less important extra information about non Adobe GREP starts here ***
On this page: http://caspar.bgsu.edu/~courses/Stats/Labs/Handouts/grepadvanced.htm, I found a piece of text dealing with this exact issue, but according to the text, different lengths of the string are allowed, as long as they all have a fixed length (i.e. no wildcards in side the lookbehind expression):
The contents of a lookbehind assertion are restricted such that all the strings it matches must have a fixed length. However, if there are several alternatives, they do not all have to have the same fixed length. Thus
(?<=Martin|Lewis)
is permitted [...]
*** Unimportant extra information about non Adobe GREP ends here ***
The author of the caspar.bgsu.edu page above also writes that several assertions can be added one after another:
Several assertions (of any sort) may occur in succession. For example,
(?<=\d{3})(?<!999)foo
matches "foo" preceded by three digits that are not "999". Notice that each of the assertions is applied independently at the same point in the subject string.
But I tried that as well, using this GREP with separate assertions for the positive lookbehinds in my example:
(?<=open)(?<=enter).+
... resulting in no match at all:
I don't know what point this is in Jongwares nice GREP flavour of Indesign help file, it might be there, just that I don't know the correct terminology.
Not much of a question this, but perhaps it could be a subject for a discussion anyway. Not the least if my observations are incorret.
Thanks,
Andreas Jansson