Skip to main content
Inspiring
August 14, 2018
Answered

grep search

  • August 14, 2018
  • 2 replies
  • 1065 views

I would like to save a grep search. I have some words to which I have to assign a change of style. These words increase with time, so my search and replacement must be saved and modified over time. Basically I have to say search word a, word b, word c ... (etc) and replace with word to change style, word b change style, word c change style (etc.) how can I do? Over time these words increase. Basically I have to search for numerous words and insert a wild card after them.

    This topic has been closed for replies.
    Correct answer Stephen Marsh

    Cool winterm – thanks for sharing, I did not know about the (?i) option to make a case insensitive search at the beginning (looks like it may also possible to use other flags such as global and multiline). Your pattern does simplify things, cheers!

    2 replies

    Stephen Marsh
    Community Expert
    Community Expert
    August 15, 2018

    I initially thought that you were looking for a GREP Find/Change, which you could still use – however that is very manual even with saved queries… So, I would recommend a Paragraph Style that references a GREP Style using the required Character Style. All you would do is continually update the regular expression used in the GREP style and it would be automatically applied to the document.

    Stephen Marsh
    Community Expert
    Community Expert
    August 15, 2018

    Here is an example of a Find/Change using GREP and a character style. The first word that a new style is to be applied to is: dog or Dog or DOG

    The Find pattern is: \b[D|d]og\b|\bDOG\b

    Then you can edit the pattern to use the second key-word, such as: cat or Cat or CAT

    The updated/saved/overwritten Find pattern is: \b[D|d]og\b|\bDOG\b|\b[C|c]at\b|\bCAT\b

    Other valid variations would also include:

    \s[D|d]og\s|\sDOG\s|\s[C|c]at\s|\sCAT\s

    [D|d]og | DOG | [C|c]at | CAT

    I am not sure if there is a limitation on the length of the GREP find string and of course it can be hard to understand what is going on (which is why I have added faux coloured syntax highlighting in my examples)… the visibility of the entry field is limited in the Find or GREP Style interface, so it may be easier to copy/paste the regular expression to/from a text editor where you will have better visibility.

    P.S. There is no need to replace the word, just replace the style.

    ______________________

    However, as I mentioned earlier, I believe that a Paragraph Style that references a GREP Style/Character Style is the better way to go:

    winterm
    Legend
    August 14, 2018

    Could you elaborate a bit more, preferably with real samples?

    Assuming a wildcard refers to a character that can be substituted for zero or more characters in a string, what exactly you want to insert after found words?

    Say, \d is a wildcard for any digit. You can enter it in a Find what field, but not in Change to.