3

I'm attempting to limit the length of a displayed string to the first 50 characters plus any needed to end at the next word boundary. I'm using the regex_replace filter in the template tag to replace all the characters after the pattern match with "...". However, using the positive lookbehind requires the less-than symbol which apparently MT is interpreting as the start of a tag. This is causing nearby tags to break and the template fails to publish, reporting an error. It there any way to incorporate the positive lookbehind into the template?

<mt:Ignore>Limit entryTitle length by discarding any/all chars after whole word containing 50th char</mt:Ignore>
<mt:entryTitle regex_replace="/((?<=.{50}\b).+)/i","...">

1 Answers1

0

This is an XML problem: The "<" character is illegal within a tag. Encode it as &lt;:

<mt:entryTitle regex_replace="/((?&lt;=.{50}\b).+)/i","...">
Bohemian
  • 412,405
  • 93
  • 575
  • 722
  • I was going to suggest the exact same thing, but there's one thing I'm not certain about. From my understanding `<` and `&` are both illegal characters in XML tags. Does `<` need to be escaped as `\<` because of `&`? – l'L'l May 16 '14 at 21:07
  • @l'L'l it doesn't need escaping, because the character sequence `<` is a special XML entity (treated as a single "thing"). You can test it yourself [here](http://www.w3schools.com/xml/xml_validator.asp) – Bohemian May 16 '14 at 23:18