In InDesign, I’m using the GREP expression (?<=.)/(?=.)
to locate all occurrences of the slash character /
throughout a document.
For example, I want to find the character /
in Color/Colour
or American English/British English
in order to apply a certain styling to the slash.
However, I want to limit this to all words/strings that do not begin with either http
or www
, so the slashes in https://usa.gov/about
or www.gov.uk/about
should not be included in the results. Lone slashes should/can be ignored.
I have managed to find all words/strings that begin with either http
or www
with \<www|\<http
, however, I’m not able to combine the two.
I’ve tried the following but with no success:
(?<=.)(?<!\<www|\<http)/(?=.)
From what I can see, InDesign uses the Perl Regular Expression Syntax boost libraries.
If the regex engine is boost as you state in your comment, you could make use of SKIP FAIL backtracking control verbs to first match what you don't want and then skip the match:
(?<!\S)(?:(?:https?|www)\S+|/+(?!\S))(*SKIP)(*F)|/
The pattern matches:
(?<!\S)
Assert a whitespace boundary to the left(?:
Non capture group for the alternatives
(?:
Non capture group
https?
Match http or https|
Orwww
match literally)
Close the non capture group (You might append \b
here for a word boundary)\S+
Match 1+ non whitespace characters|
Or/+
Match 1 or more times /
(?!\S)
Assert a whitespace boundary to the right)
Close the non capture group(*SKIP)(*F)
Skip the match|
Or/
Match /
See a regex demo.