2

I have some HTML in a text and I would like to apply a character style to the HTML tags:

<p>This is some <strong>HTML</strong> I want to use.</p>

I want to only change the tag name, not the < or >. In other words, I want to change the style of the p but not the enclosing <>.

Normally, I would use: \<(.*?)\> to capture the group inside the brackets, but InDesign includes the brackets!

4

Its not a good idea to parse HTML with regular expressions (GREP). ;(

Why are you esscaping the < and > chars? they should have no specific meaning in regular expressions. Try <(.*?)> or even better <([^<>]*)>. But that matches the entire thing tough it has a matching group, you can use it to replace, but it does not alter the selection. So what you need is something different.

Look ahead and look behind operator

You can find them under the match group. In this case they are positive look ahead/behind objects. What this does is it matches if these things surround the match So your regexp becomes:

(?<=<)([^<>]*)(?=>)

There exits also something called negative lookaheads/behinds that matches if match is not present.

| improve this answer | |
0

Turns out that it was working, but character styles were overriding paragraph styles. :(

FWIW, joojaa is right that the < and > don't need to be escaped, and his regex is probably a lot more robust.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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