-
1. Re: Help with GREP Query
Eugene Tyson Apr 27, 2010 9:16 AM (in response to Skempy)(?<=“).+?(?=”)
If you just copy and paste the opening and closing quotes where the quotes are here it works.
For some reason the code ~{ and ~} won't work for me?
But copying and pasting the quote in does work.
This does work too
(?<=~{).+?(?=~})
But it also finds the space between quotes next to each other like: "123" "345"
-
2. Re: Help with GREP Query
Eugene Tyson Apr 27, 2010 9:22 AM (in response to Eugene Tyson)You actually need this
(?<=\=“).+?(?=”)
if it's to follow an equals
I copied your text above there and it works fine for me.
There looks to be closing quotes after the "prompt" "" width="250"
before 250 it make sure it's an opening mark
-
3. Re: Help with GREP Query
[Jongware] Apr 27, 2010 10:22 AM (in response to Eugene Tyson)To display as code, I'd not use the smart curly quotes and use plain old straight-up ' and ".
(And also be sure to switch off ligatures -- some versions of (for example) Courier and Letter Gothic have, for no apparent reason at all, "fi" and "fl" ligatures. They sure makes your #define's look weird.)
-
4. Re: Help with GREP Query
Eugene Tyson Apr 28, 2010 2:18 AM (in response to [Jongware])Jongware - I don't know why - but using the straight quotes and typing them into the GREP window has varied success.
However, when I copy and paste them from the text I get the "curly" quotes in the GREP text insertion area. And that works a lot better for some reason?
-
5. Re: Help with GREP Query
Skempy Apr 28, 2010 4:11 AM (in response to Eugene Tyson)@Jongware: thanks for the hint about ligatures.
I have Typographer's Quotes turned off and have pasted the code in from Notepad. All the quote marks are the same. I have pasted a quote mark into the Grep statement to make sure.
But this: (?<=\=").+?(?=")
gives the following:
<grep="red" grep="red" grep="red">
until the second set of quote marks is empty, then this happens:
<grep="red" grep="" grep="red">
This is not a major problem for me but I have been singing the praises of Grep Styles to colleagues and would really like to solve this one.
Thanks
-
6. Re: Help with GREP Query
L. Tournier Apr 28, 2010 4:40 AM (in response to Skempy)Hello
You could try this regex with a negative class:
(?<=\=")[^"]+?(?=")
-
7. Re: Help with GREP Query
[Jongware] Apr 28, 2010 4:43 AM (in response to Skempy)The GREP style is not applied to plain
text=""
because of the '.+?' combo -- there needs to be at least one character. At least that sounds logical -- but I agree, it seems that right after that, the GREP is so confused that it just plain stops working.
Now I would have thought that this one
(?<==")[^"]+(?=")
should have worked, because it should simply scan for "not a double quote" -- but that does not work. It does nothing --, even though the syntax is perfectly okay.
First, I found this one works:
(?<==")(?!").+?(?=")
(any sequence of characters, where the first is not a quote). But after some more experimenting, I found the "logical" way does not work because of the " character in the lookbehind.
If you fix that by replacing it with its Unicode value \x{22}, it suddenly works again. This is the most simple form that works:
(?<==\x{22})[^"]+(?=") -
8. Re: Help with GREP Query
[Jongware] Apr 28, 2010 4:46 AM (in response to L. Tournier)Laurent, that does not work, not even in the regular GREP search box! Quite a nasty surprise.
It seems the lookbehind has a problem with quotes -- double as well as single. I bet it has something to do with the smart quotes translation, where the plain " character searches for straight double quotes as well as curly double open and close. Perhaps this needs a bug report :-)
-
9. Re: Help with GREP Query
[Jongware] Apr 28, 2010 4:50 AM (in response to [Jongware])Just FYI, the single quote has exactly the same problem. You can solve it the same way: replace the first single quote with its hex code:
(?<==\x{27})[^']+?(?=') -
10. Re: Help with GREP Query
[Jongware] Apr 28, 2010 5:00 AM (in response to [Jongware])And, in case you're thinking it's not already a total mystery:
I wondered what would happen with curly quotes. After all, the GREP search ought to treat all of them the same. Well -- it does not work. The code "\x{22}" forces a straight double quote, so it will never match the curly ones. Fortunately, you can use an inclusion group in the lookbehind:
(?==[straight quote + curly open quote + curly close quote])
(written out in full so you can see what I did.) But I accidentally stumbled upon this:
(?<==["])[^"]+?(?=")
... it works for all possible combinations of straight, curly open, and curly close quotes ... Remove the [ ] in the lookbehind and it doesn't work anymore. Add them and it works again.
-
11. Re: Help with GREP Query
L. Tournier Apr 28, 2010 5:02 AM (in response to [Jongware])Hello Jongware
This strange, it is OK for me
There are some problems with quotes (cf. http://www.indigrep.com/index.php?post/2009/08/04/Les-guillemets-GREP-%3A-utiles)
Depending of OS and version of InDesign ? (I am using XP pack 3 and CS4)
-
12. Re: Help with GREP Query
[Jongware] Apr 28, 2010 5:14 AM (in response to L. Tournier)Il est totallement correct... the one code I did not try was ~"
-
-
14. Re: Help with GREP Query
Eugene Tyson Apr 28, 2010 5:34 AM (in response to Skempy)Good work - I see I've been outclassed in the GREP syntaxes once again
Although I didn't have Cs4 to test out the GREP style and I was working with CS3 and doing search and replace which seemed to work fine.
I'll have to give the code a whirl in CS4 when I get to that computer later on today.
-
15. Re: Help with GREP Query
Eugene Tyson Apr 28, 2010 9:17 AM (in response to Eugene Tyson)How odd this GREP style thing is
This works for some reason
even though I only have \w+ it still picks up the numbering?
I originally thought I could just add a GREP style, for letters, for numbers, for whatever, anything but quotations - you can add in more GREP styles. When I put in the first one everything turned red and I was surprised.
-
16. Re: Help with GREP Query
[Jongware] Apr 28, 2010 1:56 PM (in response to Eugene Tyson)Nah. "Word characters" is not limited to just alphabetics: http://www.anybrowser.org/bbedit/grep.shtml#SearchChars (entry under \w):
According to the release notes: "A word is any run of non-word-break characters bounded by word breaks. Word characters in the ASCII range are generally alphanumeric, and characters whose value is greater than 127 are also considered word characters."
Skempy's samples show just single-word stuff, so apparently you don't need to add spaces, but for other HTML attributes you have to add at least "-" (for negated numbers), "#" (for colors and anchor names), "%" (for table widths), and just about everything that may appear in a file path.
[Post-ed] Oh, and you need to adjust Skemp's examples a bit:
prompt"" should, for a fair comparison, actually be prompt=""
And it's funny (sort of) to see (?<=\=") -- you don't need the backslash because the equals sign is not "special" -- even although it is used inside a 'special' context. There is no way the characters "?", "=", "<", and "!" can be combined in such a way you'd need to escape one of them if they are not to be seen as a part of the lookahead/lookbehind.
-
17. Re: Help with GREP Query
Eugene Tyson Apr 29, 2010 1:30 AM (in response to [Jongware])That's very interesting I didn't realise that \w+ would pick up numbers too - I should be more careful about using that syntax - I figured because \d picked up digits the \w picked up just letters.
Thanks for the explanation.
-
18. Re: Help with GREP Query
Skempy Apr 29, 2010 2:33 AM (in response to Eugene Tyson)Thanks to everyone for their input. I have learnt a bit more as well as solving my immediate problem.
My colleage is now reading both Peter Kahrel's GREP in InDesign CS3 and Michael Murphy's guide too.
Thanks again, interesting reading.
Simon Kemp.









