: Change HTML tag styles with GREP in InDesign 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 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!
More posts by @Michele215
2 Comments
Sorted by latest first Latest Oldest Best
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.
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.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.