Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Escaping curly braces (replace function)

Chuck
2008-03-12
2012-10-08
  • Chuck
    Chuck
    2008-03-12

    Hello,
    I can't seem to get the escaping right to replace the curly braces characters {}...

    <xsl:value-of select="replace($entered_string, 'magic regular expression', 'replacing with two brackets')"/>

    I'm using Saxon9B (with Oxygen)

    Tried:
    <xsl:value-of select="replace($entered_string,'{','{{')"/>
    Oxygen validates this, but when I run it, I get "Invalid replacement string in replace(): \ character must be followed by \ or $"
    If I try:
    <xsl:value-of select="replace($entered_string,'{{','{{{{')"/>
    Oxygen won't validate, I get "Error at character 0 in regular expression "{{": expected end of string

    Apologies if this is the wrong forum...

    Thanks,
    Chuck

     
    • Michael Kay
      Michael Kay
      2008-03-12

      The curly brace needs to be escaped as { in the regular expression, but it does not need to be (and must not be) escaped in the replacement string. So it's

      replace($in, '{', '{{')

       
      • Chuck
        Chuck
        2008-03-12

        Thanks much!