GREP, how to select everything except a specific word

Learn / Forums / InDesign User Groups / GREP, how to select everything except a specific word

Viewing 10 reply threads
  • Author
    Posts
    • #87913

      It´s easy with GREP to select the word “shining” in the text below.

      But how do you do the opposite, select everything EXCEPT the word “shining” ?

      “The sun was shining the whole day”

      I have tried this code [^shining]
      This does the job, but also choose letters from the other words, which is not what I want.

    • #87917
      David Blatner
      Keymaster

      Yes, when you put characters in square brackets, such as [abc] it means “any one of these.” And the caret means “not” so [^abc] means “not any of these.”

      You would probably have to do something like .+?(?=shining) to grab the text before the word (that’s a “positive lookahead”), and then use a positive lookbehind to capture the text after the word.

    • #88097

      Thank you David,
      The first code did the trick, but I couldn´t get the other side of “shining” to be selected.

    • #88099
      David Blatner
      Keymaster

      InDesign cannot select discontiguous text at the same time. You would have to select one, then the other.

    • #88111

      Okay, now I got it.

      First line of GREP code: .+?(?=shining)
      Second line of GREP code: (?<=shining).+

      Everything except “shining” is selected.
      Thank you once again David.
      Thomas

    • #88112
      Matt Isaac
      Participant

      This also only works if “shining” only appears once in the paragraph.. if you need it to ignore two or more of the word you may need to use a script depending on what you are doing with the text after it is selected.

    • #89492

      Hi,

      If you want to catch all text except: “Thomas”, “David”, “Skemicle” and … “Obi-wan”!

      Do it simply:

      Create a ‘not_Catch” condition and apply it to the words you don’t want to be catched:

      Find: \b(Thomas|David|Skemicle|Obi-wan)\b
      Replace by format: ‘not_Catch’ condition

      Now, you just have to do this:

      Find: (?s).+ + Non conditional

      … and make what you want!

      Simple to script! … I let you do it! ;-)

      (^/)

    • #90357
      Donna Morris
      Member

      newbie with Grep and InDesign.. Loving it to control styling. This was the closest clue I could find in the forum. BUT I need the whole string with a changing number.

      I need to apply specific styling — mostly changing the font size. I have three styles working.
      SOLD (?-i)\b(SOLD)\b
      JUST LISTED (?-i)\b(JUST LISTED)\b
      UNDER CONTRACT (?-i)\b(UNDER CONTRACT)\b
      This will be feed as data to my text — and I can control that the above will always be this text.

      Problem:
      I need a different font size for “UNDER CONTRACT IN 23 DAYS” & “SOLD IN 23 DAYS” — the number of days may change.
      I need to create GREP to find those strings even when the number of days is different. — Right now it only works if I type in “UNDER CONTRACT IN 23 DAYS” exactly I can’t get it to work if the number changes. The style needs to be applied to the entire string.

      Thanks in advance for anyone who can shed some light :-)

    • #90359
      David Blatner
      Keymaster

      This probably isn’t the most elegant way, but you could search for [(UNDER)|(SOLD)].+?(DAYS)
      That will find any sentence that starts with “under” and ends with “days” (in all caps)

    • #90363

      Just:

      (UNDER\hCONTRACT|SOLD)\hIN\h\d+\hDAY(S)?

      (^/)

    • #90365
      Donna Morris
      Member

      Thank you for your feed back!!!!!

      Seems both your solutions would apply the same style to the text. I needed separate styles.
      Kept searching around before both of your replies:
      I’m using this:

      Style 1 ^.*CONTRACT IN.*$
      Style 2 ^.*SOLD IN.*$

      So far that seems to work.

      On the same Project — my next challenge is to Change Style based on Character count in a text box… Is that possible with Grep? — should i make a new post?

Viewing 10 reply threads
  • You must be logged in to reply to this topic.
>