GREP, how to select everything except a specific word
Learn / Forums / InDesign User Groups / GREP, how to select everything except a specific word
Tagged: GREP selecting
- This topic has 10 replies, 5 voices, and was last updated 7 years, 4 months ago by Donna Morris.
-
AuthorPosts
-
-
August 30, 2016 at 6:01 am #87913Thomas Liptak vonMember
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. -
August 30, 2016 at 6:57 am #87917David BlatnerKeymaster
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. -
September 1, 2016 at 10:32 am #88097Thomas Liptak vonMember
Thank you David,
The first code did the trick, but I couldn´t get the other side of “shining” to be selected. -
September 1, 2016 at 11:01 am #88099David BlatnerKeymaster
InDesign cannot select discontiguous text at the same time. You would have to select one, then the other.
-
September 1, 2016 at 1:26 pm #88111Thomas Liptak vonMember
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 -
September 1, 2016 at 1:33 pm #88112Matt IsaacParticipant
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.
-
November 1, 2016 at 1:27 pm #89492Michel Allio for FRIdNGEParticipant
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’ conditionNow, you just have to do this:
Find: (?s).+ + Non conditional
… and make what you want!
Simple to script! … I let you do it! ;-)
(^/)
-
December 7, 2016 at 8:42 am #90357Donna MorrisMember
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 :-)
-
December 7, 2016 at 9:49 am #90359David BlatnerKeymaster
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) -
December 7, 2016 at 10:41 am #90363Michel Allio for FRIdNGEParticipant
Just:
(UNDER\hCONTRACT|SOLD)\hIN\h\d+\hDAY(S)?
(^/)
-
December 7, 2016 at 11:02 am #90365Donna MorrisMember
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?
-
-
AuthorPosts
- You must be logged in to reply to this topic.