Layer7 API Management

Expand all | Collapse all

How To Precede "\" before Special Characters + - && || ! ( ) { } [ ] ^ " ~ * ? : /

Jump to Best Answer
  • 1.  How To Precede "\" before Special Characters + - && || ! ( ) { } [ ] ^ " ~ * ? : /

    Posted 06-15-2017 12:33 AM

    I have a query Regarding : How to Use Regular Expression to precede any Special Character with “\” eg “(“ with ”\(“. I need to search name using solr, because solr is not accepting special character I need to append  “\”  before every  special character Like + - && || ! ( ) { } [ ] ^ " ~ * ? : / . I am using Evaluate Regular Expression assertion.  

    Eg. Akash (Raj) to Akash\\(Raj\) and 

    \(1\+1\)\:2



  • 2.  Re: How To Precede "\" before Special Characters + - && || ! ( ) { } [ ] ^ " ~ * ? : /
    Best Answer

    Posted 06-16-2017 12:44 PM

    If I understand correctly (not that I see a question there), you want to use the regex assertion with 'match and replace' option and search string:

    ([\+\-\&\|\!\(\)\{\}\[\]\^\"\~\*\?\:\/\.])

    with a replacement of:

    \\$1



  • 3.  Re: How To Precede "\" before Special Characters + - && || ! ( ) { } [ ] ^ " ~ * ? : /

    Posted 06-19-2017 12:29 AM

    I got the solution. i used the regex assertion "Evaluate Regular Expression assertion

    Regex [^0-9a-zA-Z*]. replacement \\$0 (Match and Replace)and its working .



  • 4.  Re: How To Precede "\" before Special Characters + - && || ! ( ) { } [ ] ^ " ~ * ? : /

    Posted 06-19-2017 04:50 PM

    In that case && would be replaced with \&& instead of \&\&, and keep in mind that $0 is the entire matched string where $1 is only the first capture group.



  • 5.  Re: How To Precede "\" before Special Characters + - && || ! ( ) { } [ ] ^ " ~ * ? : /

    Posted 06-20-2017 12:46 AM

    Hi Ben,

    Thanks for Reply, My Requirement Was to Replace && with \&&. that's why i used $0.