-
1. Re: GREP Expresson - limit to whole word
[Jongware] Apr 23, 2009 8:48 AM (in response to Marvin Sable)How could it be better than this? That's the right way to do it.
OTOH, you don't have to have a selection group (x|y) -- for a single character, it's easier to type [xy] (an 'or' group). The selection group can be used in case you want to search for entire strings (or large parts of strings), like (Sun|Mon|Tues|Wednes|Thurs|Fri|Satur)day
-
2. Re: GREP Expresson - limit to whole word
Eugene Tyson Apr 23, 2009 8:53 AM (in response to Marvin Sable)What are you trying to search for?
-
3. Re: GREP Expresson - limit to whole word
Marvin Sable Apr 23, 2009 9:01 AM (in response to Eugene Tyson)No particular search now. I'm just trying to learn proper search methods. I see (Sun|Mon| …)----- etc is more elegant but still have issue.
If I search for (Sun|Mon|Tues|Wednes|Thurs|Fri|Satur)day I will also get Sundaybest (although not a proper word it demonstrates the point. So how do I limit the find to whole word Sunday, Monday, etc.
(cat|dog) finds cat, dog, catatonic and dogmatic -
4. Re: GREP Expresson - limit to whole word
Eugene Tyson Apr 23, 2009 9:25 AM (in response to Marvin Sable)Why not just search for
Sunday|Monday etc.?
Or if you just wanted to search for the first 3 letters with day at the end of it you could do
\<\w\w\w(?=.+day)
That's a Possitive Look Ahead
(?=.+day)
So what you're saying to do is only find the first 3 letters at the begining of a word, then look at the rest of the word, if it has any character (.+) and day (.+day) up to the end of the word then only search for the first 3 letters that match that.
No other words will be found unless they end in -day like "today"
So to revise that you would do something like this
Sun|Mon|Tue|Wed|Thu|Fri|Sat|(?=\.+day)
Being more specific.
But it all depends on what you're looking for.
You can find inbetween characters like say (ok this is a lame example but you get the drift)
Chapter 1: Dinosaurs – Paleontologists
and say you want "chapter 1" and "dinosaurs" to be to be a character style so it becomes a running head but you don't want to find all Chapter 1 references, or perhaps chapters are referenced in the text so you could modify the GREP to be
Chapter \d+(?=\:)|(?<=\:\s)Dinosaurs(?=\s~=)
Then you could apply your character style because it's finding just Chapter 1 etc. but only before a Colon and it's finding only Dinosaurs after a colon but before an en dash.
-
5. Re: GREP Expresson - limit to whole word
Harbs. Apr 23, 2009 11:03 AM (in response to Marvin Sable)I always find \b much easier to remember and read than \< and \>
using \b to delineate word boundaries in your example would be this:
\bc(a|o)t\b
I wonder if there's a performance difference...
Harbs
-
6. Re: GREP Expresson - limit to whole word
Marvin Sable Apr 23, 2009 11:13 AM (in response to Harbs.)Harbs
Exactly what I was looking for. I needed the way to find a string (whatever it might be) that appeared by itself and not as part of a larger string. I wanted to be able to find cat but not the cat in catatonic.
Thanks
Marvin
-
7. Re: GREP Expresson - limit to whole word
Marvin Sable Apr 23, 2009 11:23 AM (in response to Harbs.)>>> and I'm getting the same result when I use Beginning of Word and End of Word as when I use Word Boundary so I''m wondering when does one know when choosing one over the other makes a difference.
-
8. Re: GREP Expresson - limit to whole word
Harbs. Apr 23, 2009 11:39 AM (in response to Marvin Sable)Marvin Sable wrote:
>>> and I'm getting the same result when I use Beginning of Word and End of Word as when I use Word Boundary so I''m wondering when does one know when choosing one over the other makes a difference.
I don't think there's a practical difference between the two. I just find it easier to keep one code in my brain from falling out instead of two.
Also \B is a negated word boundary so you can do something like \bcat\B which will find the first three letters of catatonic but will not find "cat"...
-
9. Re: GREP Expresson - limit to whole word
Marvin Sable Apr 24, 2009 12:48 PM (in response to Harbs.)Right - the Capital version of the letter reverses its effect. So it will find CAT when it is Part of a word only.
It seems like there are most often more than one way to create an expression. So if it works it right.
Thanks again.




