Mobile app version of vmapp.org
Login or Join
Michele215

: 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>

@Michele215

Posted in: #AdobeIndesign #CharacterStyles #Grep #Html

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!

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Michele215

2 Comments

Sorted by latest first Latest Oldest Best

 

@Michele215

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.

10% popularity Vote Up Vote Down


 

@Yeniel278

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme