Skip to main content
Participant
August 24, 2024
Question

How to limit GREP search to words which do not start with certain characters?

  • August 24, 2024
  • 1 reply
  • 678 views

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.

 

As a next step, I want to limit this to all words/strings that do not begin with either https, https 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 be ignored. How can this be achieved?

 

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, based on an answer to my question on Stack Overflow (https://stackoverflow.com/a/78494627/3103254), which should work with the boost regex engine InDesign GREP is using (https://community.adobe.com/t5/indesign-discussions/grep-what-is-the-base-syntax-of-indesign-grep/td-p/10321905), however, while this works fine in a testing environment (https://regex101.com/r/a0x0zG/1), this does not seem to work in InDesign: (?<!\S)(?:(?:https?|www)\S+|/+(?!\S))(*SKIP)(*F)|/

This topic has been closed for replies.

1 reply

Robert at ID-Tasker
Legend
August 24, 2024

What do you want to do with found text? 

 

Are you changing its contents - by adding / removing characters - or you just want to change formatting / appearance?

 

InDesign uses its own implementation of RegExp. 

 

 

Would be extremely easy to achieve with my tool - first, find everything with "/" then filter out web addresses or limit even more, then do whatever you want to do with what's left - but you are probably looking for a free solution / it's a one-off / you work on a Mac? 

 

 

If it's just styling / formatting - why not do it in two steps: 

1) apply whatever styling / formatting you want to all texts meeting your criteria, 

2) "reset" all web links. 

 

Participant
August 25, 2024

Thank you, Robert.

 

Yes, I would love to achive this / learn how to achieve this with InDesign GREP without third-party tools. And yes, I’m working on a Mac.

 

The goal is not to apply styling, but to run a search replace through multiple documents that allows me to

  1. either skip a search result, e.g. if the / is found in Berlin/London, i.e. Word/Word
  2. or replace result, e.g. if the / is found in Mexico City/New York, i.e. Multiple Words/Multiple Words (as in German this should be Mexico City / New York, i.e. with a space on both sides of the /).
Participant
August 25, 2024

To clarify the context: in the documents there are many instances of URLs starting with https, http or www, which do contain a lot of /, e.g. https://example.org/path/to/subpage In order to cut down the time on the search replace, mentioned above, I’d like to exclude these URLs from the search.