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



     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:




    And below is the policy:


    <?xml version="1.0" encoding="UTF-8"?>
    <wsp:Policy xmlns:L7p="" xmlns:wsp="">
    <wsp:All wsp:Usage="Required">
    <L7p:AssertionComment assertionComment="included">
    <L7p:Properties mapValue="included">
    <L7p:key stringValue="RIGHT.COMMENT"/>
    <L7p:value stringValue="This assertion will remove all line breaks and put everything in single line."/>
    <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:Base64ResponseBody stringValue="JHtyZXF1ZXN0Lm1haW5wYXJ0fQo9PT09PT09PT09PT09PT09PT09PT0KJHtvdXRwdXR9"/>
    <L7p:EarlyResponse booleanValue="true"/>
    <L7p:ResponseContentType stringValue="text/html; charset=UTF-8"/>



    Please help.




  • 2.  Re: How to remove newline characters

    Posted 05-05-2017 08:16 AM

    Hi Siddharth,


    Try this expression:







  • 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.




  • 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: