Announcement

Collapse
No announcement yet.

Replace '\E' from URL link using replace method

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Replace '\E' from URL link using replace method

    var str='\E\\E\10.1.2.154\E\bcs\E\30877_P9999_Adult{2} _02_05_2019_0329p.pdf';
    var res=str.replace('\E', '');
    logger.debug(res);
    ---------------------------------------------------------------------
    When I try run a script, it giving me an out put like :
    --------------------Java script return like this --------------------
    [2019-02-13 15:06:30,001] DEBUG (js-connector:?):

    \E.1.2.154EcsE877_P9999_Adult{2}_02_05_2019_032 9p.pdf

    ---------------------------------------------------------------------
    it does not get replaced . I am expecting final out like this
    \\10.1.2.154\bcs\30877_P9999_Adult{2}_02_05_2019_0 329p.pdf



    -----------------------------

    Any quick advise on this

  • #2
    You have to quote the backslash:
    Code:
    var str='\E\\E\10.1.2.154\E\bcs\E\30877_P9999_Adult{2}  _02_05_2019_0329p.pdf';
    var res=str.replace(/\\E/g, '');
    logger.debug(res);
    Last edited by odo; 02-14-2019, 07:34 AM. Reason: Oops, has to be javascript notation, of course...

    Comment


    • #3
      I am getting output like : E.1.2.154EcsE877_P9999_Adult{2}_02_05_2019_0329 p.pdf

      I am expecting output like : \\10.1.2.154\bcs\30877_P9999_Adult{2}_02_05_2019_0 329p.pdf


      ---------------------------------------
      When I try on seperate java script latest version - its working fine with below code


      var str=String.raw`\E\\E\10.1.2.154\E\bcs\E\30877_P999 9_Adult{2}_02_05_2019_0329p.pdf`;
      var res=str.split(String.raw`\E`).join('');

      console.log(res);

      -----------------------------------------------------------------------------------
      String.raw does not supported by mirth java script . Please advise

      Comment


      • #4
        Please try again, I edited my post above. The regex has to be javascript notation.

        Comment


        • #5
          No luck this time too.
          [2019-02-15 09:56:50,001] DEBUG (js-connector:?):
          E .1.2.154E csE 877_P9999_Adult{2} _02_05_2019_0329p.pdf

          I am getting as above.

          Comment


          • #6
            Originally posted by odo View Post
            You have to quote the backslash
            You have to escape the backslash in the input string, too.
            Code:
            var str='\\E\\\\E\\10.1.2.154\\E\\bcs\\E\\30877_P9999_Adult{2}_02_05_2019_0329p.pdf';
            var res=str.replace(/\\E\\/g, '\\');
            logger.debug(res);
            Last edited by agermano; 02-15-2019, 05:45 AM.

            Comment

            Working...
            X