Skip to main content
James Gifford—NitroPress
Legend
July 17, 2024
Question

InDesign GREP chart

  • July 17, 2024
  • 9 replies
  • 10956 views

I've recently uploaded a GREP list/cheat sheet/reference card to a couple of topics. It's one I created a few years ago and have been updating for my own uses, since I can't seem to find one that meets all my wishes — complete, accurate, organized, reasonably tidy-looking and without the points of murky example or understanding that so many of the references out there seem to have. (Okay, I'm fussy.)

 

After my upload yesterday I noticed an error, and some omissions, and one thing led to another, and so — very polished version of what I think a GREP reference should be is attached. I hope both newcomers and grizzled GREPpers find it useful.

 

PDF and IDML also available on my digital publishing reference site.

 

All due credit, both in general and as a resource for this update/polishing round, to @Peter Kahrel 's authoritative GREP in InDesign.

 

[Older version removed; updated file in later post.]

9 replies

Mike Witherell
Community Expert
Community Expert
February 19, 2025

Just wanted to say I'm enjoying this discussion in the deep end of the swimming pool. I'm enjoying the learning, and it gives me insights when teaching GREP to others. Thanks James, Mark, Peter, Robert, and all you code-oriented folks on this extraordinary forum!

Mike Witherell
Robert at ID-Tasker
Legend
February 19, 2025

@Mike Witherell

 

No need to thank me, I'm just a village idiot here. 

 

m1b
Community Expert
Community Expert
February 19, 2025

@Robert at ID-Tasker you are no village idiot!—you are an expert like each of us. I have made many more errors than you have on this one thread—some quite embarassing—so on that metric I would win the village idiot olympics here.

 

We could, as time permits, go back and look over our contributions on a thread such as this, and analyze the contribution we made. Did our comments push forward the discussion, or side-track it?

 

I find it uncomfortable work, as I see all my mistakes, but it can be edifying.

- Mark

Peter Spier
Community Expert
Community Expert
February 18, 2025

@James Gifford—NitroPress Thanks for the chart. And although this thread has become nearly impossible to follow in any navigational way, all that back and forth discussion about \K has finally, I think, given me an understanding of the functional use for it, so thanks to all the folks who chimed in about that, too.

Mike Witherell
Community Expert
Community Expert
February 15, 2025

James, I applaud your neat and orderly layout presentation. It looks nice.

 

This is the way I have been describing it (\K) in my GREP code list:

Lookbehind (keep text found out of match) ............. \K

Do you think that should be rewritten for better clarity?

Mike Witherell
James Gifford—NitroPress
Legend
February 18, 2025

Okay.

 

(1) I changed the note for non-marking expression from * "Mostly Obsolete" to "* Obsolete" to make room for a few more words about our pal \K — there not being another millimeter for text on this sheet. I settled on Mostly Obsolete after the last disucssion in which it was explained to me that 'non marking' means it doesn's use up system memory over execution, which can be, or was, important in systems with small working memory.. Since pretty much all systems have vast-to-unlimited memory these days, I suppose some massive GREP string might benefit from this efficiency twist, but my thought is anyone writing such huge search strings already knows that. So I'm changing that to "*Rarely needed in place of regular Subexpression."

 

(2) I find it amusing/vexing/frustrating that there is hardly ANY authoritative info on our pal \K... searches turn up little but brief notes and/or endless discussion/argument, most of which are written in pure gibberish. It isn't even included on some majority of references/charts. Were I not a compleatist, I'd just delete the whole line and be done with it; this sheet is meant for beginners to occasional GREPpers, not those who think in terms of combined lookbehind/lookahead structure. So to make the chart compleat, avoid looking like a compleat idiot to GREP-fu Masters, and make use of the limited space, I'm naming it Reset Match and making the note "†Complicated geekahol."

 

The IDML version is all yours for further, personal, deeply meaningful edits. 🙂

Peter Kahrel
Community Expert
Community Expert
February 18, 2025

@James Gifford—NitroPress 

 

If it was just about memory then I'd agree with you that there's not much need for non-marking expressions. But it's not only about memory, it's about speed as well. For the occasional GREP expression it's not going to make much difference. But if you stuff your document with GREP styles and use a lot of grouping -- expressions enclosed in parentheses -- it will certainly make a difference. 

Peter Kahrel
Community Expert
Community Expert
February 15, 2025

@James Gifford—NitroPress 

James -- Just one small comment on your excellent chart: in the Character-class box the label for \x{■} says "Hex Code (2 or 4 digit)", but that can be 1- or 3-digit too. You can omit leading zeros: \x{9} finds tab characters, \x{14b}, the eng. It's no big deal, but maybe say '1-4 digits'.

 

P.

James Gifford—NitroPress
Legend
February 15, 2025

Noted, thanks. I will probably do an update once all the dust settles here... but (re the \K thing) I did mean this to be a quickref chart and not a full annotated distillation of your book. 🙂

m1b
Community Expert
Community Expert
February 15, 2025

Hi @James Gifford—NitroPress, thanks for posting this. I think it's great!

 

I'd make one observation: that the explanation for \K is surprisingly difficult to understand for me. A clearer description, in my opinion, would be "Reset Match" or something like that. The K is usually referred to as "keep out" but that doesn't help my mental model because what it actually does is discard the current match and start again. In fact "discard" might be a good word to use. Anyway, with that in mind, the explanation via the asterisk is quite opaque, at least to me.

 

Otherwise, thanks for sharing.

- Mark

 

Edit 2025-02-16: changed "keep" to "keep out" which I hadn't remembered fully (probably due to it not really being a good explanation for what it actually does! 😛 ).

Robert at ID-Tasker
Legend
February 15, 2025
m1b
Community Expert
Community Expert
February 15, 2025

Yes Robert, I'm talking about \K. The first two links you posted give wrong information. It is not a "lookbehind" of any kind. The third post was correct.

 

But here's a more straightforward explanation, from regexr.com (my highlight in magenta rectangle):

- Mark

James Gifford—NitroPress
Legend
July 18, 2024

Thanks for the feedback, suggestions and contributions (through multiple channels) so far.

 

To make it clear, I don't intend this to be the most complete reference to GREP — not by a long shot. For one thing, the whole feature/topic is so vast and murky that there's always-always one more obscure command, another useful combo string, another trick, another limitation, etc. And we know there are many-many reference sheets, sites, pages, forums and books... some of which are even specific to InDesign's slightly specialized implementation.

 

But in going from "had a little memorized knowledge" to a fairly confident GREP journeyman over the last year, I've found the GREP "support" world to be like many others, in that there are many levels of understanding (quite a few of which are way beyond ID's uses), endless references of one kind or another, and the usual mix of reliability, currency and accuracy.

 

So I did what I do for a living (more or less, broadly speaking, all that) and created my ideal of a GREP reference, which aimed to be complete (to a specific degree), accurate (all the commands tested and the boilerplate descriptions corrected and expanded, as necessary), compact (instead of pages and pages of stuff) and, I'd hope, tidily and attractively presented. My aim was a sheet that would be of use for users across the range from "just took the training wheels off" through fairly sophisticated experts... but NOT being a tutorial for absolute newcomers or including every esoteric command/option that takes master-level experience to use. A sort of middle range tool, useful to remind the experienced and help expand the newcomers's grasp of the options. (And, without any intent to be Anglocentric or exclusionary, focused on English/Western users. I find the "let's include everyone" model of fonts, references, character/glyphs etc. a bit overwhelming given that much of that content only applies to a small percentage of users... who are usually comfortable with finding more specific support that isn't cluttered with Western specifics. 🙂 )

 

I wanted to limit the content to some core set of info, to keep it from being overwhelming or (as are many such references, especially from the Linux/programming side of things) filled with cryptic descriptions and notes. I left out POSIX, for example, because while some have it in their toolbox, it's largely redundant against more fundamental GREP commands. I left out back references and variables as much for space as for their being very complex concepts to put to use in GREP strings.

 

in short, I was aiming at a complete (to a useful level), accurate (devoid of some of the repeated errors or misleading descriptions found out there), clear (substituting clear descriptions for code-monkey-speak) and usable (clearly showing string formatting, for example) ref that was not overwhelming in content or presentation.

 

Continuing feedback welcome. 🙂

Robert at ID-Tasker
Legend
July 18, 2024

@Marc Autret's version:

 

https://www.indiscripts.com/blog/public/data/idcs4-special-characters/en_InDesignCS4-CS5-SpecialChars.pdf

 

Is missing "\W" - and maybe more from your list - but there are few extra codes - like Text Variables and Arabic/Hebrew/Bidi.

 

James Gifford—NitroPress
Legend
July 18, 2024

I'm not sure that (or ID's feature) has been updated for... quite a while. It's a great chart, very complete and well-organized; I'd expect nothing less from MA.

 

But it's pretty overwhelming and contains lots that is of little use to most users — Arabic and Hebrew characters codes simply aren't something most users need, for example. Things like back references and variables are very advanced stuff; users who can wrangle them aren't likely to need a reference chart. It has a lot more information than mine, but at the cost of being three pages long.

 

Again, as my followup post outlines, I wasn't aiming for The Last GREP Chart The World Will Ever Need, just a compact, clear, accurate one useful to the vast middle ground of InDesign (not general/programming/Linux) users. Consider it in the light of the old shareware disclaimer, "This software is guaranteed to run perfectly on the developer's computer." — "This chart is guaranteed to meet all the expectations of its creator, because he couldn't find an existing one that did."

 

But all reasonable feedback always welcome; I'd hope to make this a useful asset for that middle ground of GREP users, even if they're not me. 🙂

Participating Frequently
July 18, 2024

Many thanks for this James. 

 

 

Robert at ID-Tasker
Legend
July 17, 2024

What about all those posix-es - like "[[:punct:]]"? 

 

James Gifford—NitroPress
Legend
July 17, 2024

Do YOU see any room for them? 🙂

 

There are a few very advanced things missing from the list, partly from space and partly because they need more than a thumbnail reminder. Posix is pretty advanced, and they're all right there in the drop-down lists for those who know what they are and how to use them. Same for modifiers; things like multiline are pretty hairy to explain, and the options are clearly spelled out in the menu. (Also back-references, which are complicated AND deprecated... and I suspect there are more "unofficial" elements in there as well.)

 

But make a good argument and I'll squeeze them in.

 

ETA: I guess the case-sensitive and case modifiers are borderline. Hmm.

Robert at ID-Tasker
Legend
July 17, 2024

Myriad Pro Light Condensed and maybe 4x columns?