I have to make an e-book that contains code snippets. I am using GREP to select all code tags (bounded by <> — triangular brackets), and apply a custom style to them.

The RegEx I have developed: http://regexr.com/39puq

Works fine online.

However, it does not work in InDesign. I've attached an image (see the difference between it and the link above.

The second paragraph contains a set of indentations that InDesign just skips.

Any idea why? Am I missing something?

Thank you.InDesign Inconsistency

Later edit:

Following another StackExchange thread, I found this snippet: <.*>

However, it has the same undesired effect. Help.

2 Answers 2


Don't try to match generic XML with regexp. It will not work in many cases, use a XML parser instead and export the result. See:

In any case the grep style does not allow matches over paragraph boundaries because its not a multi paragraph parser . You can circumvent this problem tough, by replacing all end of paragraphs with forced line breaks. This causes in design to consider it one line and match better. Now your regexp would work.

Then your regexp could be simplified as:


As matching (.|/s|/S) is somewhat redundant as most of /s and /S is included in . although \n is NOT so jsut adding that one exception makes testing easier. Regexp engines in general differ in the way they handle multiline stuff so beware problems lie this way.

WARNING: This regexp won't be really robust as it does understand nested <>. So commented code may screw up royally. Use a parser to dump the stuff as RTF, much better approach.


Your problem is that the multi-line item isn't one paragraph as far as InDesign is concerned. It's 5 paragraphs.

Replace the paragraph returns with forced line breaks (Shift-Enter) and it will work as expected.

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.