Layer7 API Management

Expand all | Collapse all

How to remove newline characters

Jump to Best Answer
  • 1.  How to remove newline characters

    Posted 05-05-2017 03:37 AM

    Hi,

     

     I am trying to remove #newline characters from given string using #EvaluateRegularExpression assertion; however the output is coming blank again nag again. Below is the string in question:

     

    kPorpdbCJx6IeC3f2IOT6y8OTpeUN5Exbv8we7NilNGcSuTP3wD8gmjkAeax0bg0h5ciRMmluI8P
    rr0lqybNGw2ZvQzgflPCV0vixFeJD8qTcQv2Y/ps8unMj9eFoyuugiBatZ/VQmWT0EUfI3fhv5hN
    z9EHuhrucpgi1q2F/RFKBn8tQtTAcg7jW561x90BFGpfirK3Tzn21hDnqQ4rKp/8IY3dkYx5Rduc
    S6x5dxnZPjJcaE4Xai7CTrwgCjPy4esFJM6cWLfCDbCK6EpXgf0aYcBoM38rAADu9dE/L4WULaBW
    rJsoz2a9DC7xC6uDM9WAaNL1MskSJedExU0O1Q==

     

    And below is the policy:

     

    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="http://www.layer7tech.com/ws/policy" xmlns:wsp="http://schemas.xmlsoap.org/ws/2002/12/policy">
    <wsp:All wsp:Usage="Required">
    <L7p:Regex>
    <L7p:AssertionComment assertionComment="included">
    <L7p:Properties mapValue="included">
    <L7p:entry>
    <L7p:key stringValue="RIGHT.COMMENT"/>
    <L7p:value stringValue="This assertion will remove all line breaks and put everything in single line."/>
    </L7p:entry>
    </L7p:Properties>
    </L7p:AssertionComment>
    <L7p:AutoTarget booleanValue="false"/>
    <L7p:CaptureVar stringValue="output"/>
    <L7p:CaseInsensitive booleanValue="true"/>
    <L7p:IncludeEntireExpressionCapture booleanValue="false"/>
    <L7p:Regex stringValue="\n"/>
    <L7p:RegexName stringValue="Replace NewLine"/>
    <L7p:Replace booleanValue="true"/>
    <L7p:Replacement stringValue=""/>
    </L7p:Regex>
    <L7p:HardcodedResponse>
    <L7p:Base64ResponseBody stringValue="JHtyZXF1ZXN0Lm1haW5wYXJ0fQo9PT09PT09PT09PT09PT09PT09PT0KJHtvdXRwdXR9"/>
    <L7p:EarlyResponse booleanValue="true"/>
    <L7p:ResponseContentType stringValue="text/html; charset=UTF-8"/>
    </L7p:HardcodedResponse>
    </wsp:All>
    </wsp:Policy>

     

     

    Please help.

     

    Thanks,

    Siddharth



  • 2.  Re: How to remove newline characters

    Posted 05-05-2017 08:16 AM

    Hi Siddharth,

     

    Try this expression:

     

    /(\r\n)+|\r+|\n+|\t+/i

     

     

    Regards,

    Joe



  • 3.  Re: How to remove newline characters

    Posted 05-08-2017 07:46 AM

    Hi Joe,

     

     Newline is represented by \n . Why do we need this (/(\r\n)+|\r+|\n+|\t+/i) RegEx. Could you please explain?

    I tried this RegEx to the encrypted output of AsymmetricKeyEncryption Assertion and it is breaking Base64 encoding of encrypted output and causing teh failure at decryption.

     

    Please help.

     

    Thanks,

    Sid.



  • 4.  Re: How to remove newline characters
    Best Answer

    Posted 05-08-2017 09:25 AM

    Hi Sid,

    The best method to figuring out the exact pattern for your use case, is using an online regex tester.

     

    In the above regex, its looking for \r Carriage return character\n Line feed character\t Tab character.

     

    Excerpt from "Regular Expressions Quick Start ":

    the vertical bar or pipe symbol |, the question mark ?, the asterisk or star *, the plus sign +, the opening parenthesis (, the closing parenthesis ), the opening square bracket [, and the opening curly brace {. These special characters are often called "metacharacters". Most of them are errors when used alone.

     

    Regex Quick Reference for understanding the switches:

    http://www.regular-expressions.info/refquick.html