IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  pub.string.replace and regular expression

    Posted Mon April 12, 2010 07:05 PM

    Greetings,

    I am trying to use the pub.string.replace service to modify only the first
    occurrence of a string but am having no luck figuring out the regular expression (searchString).

    I would like to invoke the service on this string (inString):
    ‘String1 String2 String1 String2’

    and want it to look like:
    ‘String1 String2Replaced String1 String2’

    Note that I only want to change the first occurrence of ‘String2’ with ‘String2Replaced’ (replaceString).

    Any help would be greatly appreciated.

    Thanks.


    #Flow-and-Java-services
    #webMethods
    #Integration-Server-and-ESB


  • 2.  RE: pub.string.replace and regular expression

    Posted Mon April 12, 2010 07:52 PM

    using pub.string.substring built-in service to extract the value from the input string and map the result into pub.string:replace (search string) and enter the replace string value…its simple.

    HTH


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 3.  RE: pub.string.replace and regular expression

    Posted Mon April 12, 2010 08:02 PM

    Thanks but I only want to replace the first occurrence.

    Still looking for the regular expression to accomplish the task…

    Maybe my example was confusing…

    I would like to invoke the service on this string (inString):
    ‘XXXXX YYYYY XXXXX YYYYY’

    and want it to look like:
    ‘XXXXX ZZZZZ XXXXX YYYYY’

    Note that I only want to change the first occurrence of ‘YYYYY’ with ‘ZZZZZ’ (replaceString).


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 4.  RE: pub.string.replace and regular expression

    Posted Mon April 12, 2010 08:43 PM

    Using negative lookbehind:

    (?<!.*String2)String2

    would do the trick. Alas, this doesn’t work with pub.string:replace as it is presumably using a regex compiler which doesn’t support lookbehind.

    A couple of options to consider:

    • You could roll your own pub.string:replace equivalent and use the java.util.regex classes that support lookbehind.

    • Use PSUtilities.regex:replaceFirst


    #webMethods
    #Integration-Server-and-ESB
    #Flow-and-Java-services


  • 5.  RE: pub.string.replace and regular expression

    Posted Mon April 12, 2010 09:32 PM