Skip to main content
ExLibris
  • Subscribe by RSS
  • Ex Libris Knowledge Center

    GDC: Replace String with String cannot be executed with forward slashes

    • Article Type: General
    • Product: Voyager

    Problem symptoms

    Unable to use “replace string with string” consequence to replace forward slashes in a string with back slashes. Record transform fails when forward slashes are part of replace string.

    Cause

    This is result of java & rule engine syntax.

    Resolution

    When writing a “Replace String With String” rule that matches a backslash character (with the “Replace string is a regular expression” option unchecked), the “Replace String:” field must use four backslashes to match each backslash in the target record. Since the sought-after text in this instance has two backslashes, a total of 8 backslashes is required. This is due to the fact that the backslash character is an escape character in Java strings (this is not related to the use of regular expressions) and so two backslashes are needed to indicate a single backslash character. Then each of those backslashes must then be doubled again because the rule engine also regards the backslash as an escape character.

    If the “Replace string is a regular expression” option is checked then a total of eight backslashes is required to match a single backslash character, because the regular expression also considers each backslash to be an escape character.


    • Article last edited: 04-Mar-2015
    • Was this article helpful?