Topic
  • 5 replies
  • Latest Post - ‏2011-01-28T05:54:18Z by Jaango
Jaango
Jaango
274 Posts

Pinned topic pcre expression

‏2011-01-27T09:24:33Z |
I guess,this is a basic question on PCRE expression.

What should be the expression for not matching the value '127.0.0.1'
ie if the match value is 127.0.0.1 the expression will match for the value containing '127.0.0.1'
However i want the condition for not match.
Updated on 2011-01-28T05:54:18Z at 2011-01-28T05:54:18Z by Jaango
  • HermannSW
    HermannSW
    7139 Posts

    Re: pcre expression

    ‏2011-01-27T11:19:25Z  
    Hello,

    > I guess,this is a basic question on PCRE expression.
    >
    > What should be the expression for not matching the value '127.0.0.1'
    > ie if the match value is 127.0.0.1 the expression will match for the value containing '127.0.0.1'
    > However i want the condition for not match.

    Negative Lookahead assertions are the "Perl Compatible Regular Expression" (PCRE) construct you are looking for [1].
    Below PCRE will match IP addresses different to "127.0.0.1":
    
    ^(?!127\.0\.0\.1)[0-9.]+$
    

    Testing can be done with pcretest:
    
    $ pcretest PCRE version 6.6 06-Feb-2006   re> /^(?!127\.0\.0\.1)[0-9.]+$/  data> 127.0.0.1 No match data> 127.000.1 0: 127.000.1 data> 127.0+0.1 No match data> $
    


    Negative Lookahead assertions are not available for SChema Regular Expression
    (SCRE, see "XML" column in table "Lookaround" for row on "negative lookahead" [2]).

    So it depends where you want to apply your "regular" expression on DataPower ...
    Here is the output generated by attached stylesheet's regexp:test()s:
    
    a: ^[0-9.]+$ b: ^(?!127\.0\.0\.1)[0-9.]+$   a     b 127.0.0.1: 
    
    true 
    
    false 127.000.1: 
    
    true 
    
    true 127.0+0.1: 
    
    false 
    
    false 126.0.0.1: 
    
    true 
    
    true
    

    [1] http://www.regular-expressions.info/lookaround.html
    [2] http://www.regular-expressions.info/refflavors.html
    Hermann.
  • Jaango
    Jaango
    274 Posts

    Re: pcre expression

    ‏2011-01-27T13:29:37Z  
    • HermannSW
    • ‏2011-01-27T11:19:25Z
    Hello,

    > I guess,this is a basic question on PCRE expression.
    >
    > What should be the expression for not matching the value '127.0.0.1'
    > ie if the match value is 127.0.0.1 the expression will match for the value containing '127.0.0.1'
    > However i want the condition for not match.

    Negative Lookahead assertions are the "Perl Compatible Regular Expression" (PCRE) construct you are looking for [1].
    Below PCRE will match IP addresses different to "127.0.0.1":
    <pre class="jive-pre"> ^(?!127\.0\.0\.1)[0-9.]+$ </pre>
    Testing can be done with pcretest:
    <pre class="jive-pre"> $ pcretest PCRE version 6.6 06-Feb-2006 re> /^(?!127\.0\.0\.1)[0-9.]+$/ data> 127.0.0.1 No match data> 127.000.1 0: 127.000.1 data> 127.0+0.1 No match data> $ </pre>

    Negative Lookahead assertions are not available for SChema Regular Expression
    (SCRE, see "XML" column in table "Lookaround" for row on "negative lookahead" [2]).

    So it depends where you want to apply your "regular" expression on DataPower ...
    Here is the output generated by attached stylesheet's regexp:test()s:
    <pre class="jive-pre"> a: ^[0-9.]+$ b: ^(?!127\.0\.0\.1)[0-9.]+$ a b 127.0.0.1: true false 127.000.1: true true 127.0+0.1: false false 126.0.0.1: true true </pre>
    [1] http://www.regular-expressions.info/lookaround.html
    [2] http://www.regular-expressions.info/refflavors.html
    Hermann.
    Hermann,
    Thanks.
    I wanted to apply this in the deployment policy where the change configuration has to be done for the Local IP address front side Handler in case if the local ip address is not 127.0.0.1. The configuration match is */Domainname/protocol/http?Property=LocalAddress&Value=^(?!127\.0\.0\.1)http://0-9.+$. Modification type as change configuration and Configuration Value as the new ip address.
    However it is not working while import of the same WSP with the deployment policy. Do you have any thoughts.

    Also, Do you have any details on pcretest tool that you just showed. Do I have to use curl command and refer a service with the mentioned xsl to test the expression?
  • Jaango
    Jaango
    274 Posts

    Re: pcre expression

    ‏2011-01-27T15:53:49Z  
    • Jaango
    • ‏2011-01-27T13:29:37Z
    Hermann,
    Thanks.
    I wanted to apply this in the deployment policy where the change configuration has to be done for the Local IP address front side Handler in case if the local ip address is not 127.0.0.1. The configuration match is */Domainname/protocol/http?Property=LocalAddress&Value=^(?!127\.0\.0\.1)http://0-9.+$. Modification type as change configuration and Configuration Value as the new ip address.
    However it is not working while import of the same WSP with the deployment policy. Do you have any thoughts.

    Also, Do you have any details on pcretest tool that you just showed. Do I have to use curl command and refer a service with the mentioned xsl to test the expression?
    Worked with ^(?!127\.0\.0\.1)http://0-9.$
    :)
  • HermannSW
    HermannSW
    7139 Posts

    Re: pcre expression

    ‏2011-01-27T20:40:41Z  
    • Jaango
    • ‏2011-01-27T15:53:49Z
    Worked with ^(?!127\.0\.0\.1)http://0-9.$
    :)
    Maneesh,

    your last comment did not show all details, here is it again for completeness:
    > Worked with ^(?!127\.0\.0\.1)[0-9.]$
    > :)
    

    You should put output with special characters inside {code} tags.
    > Also, Do you have any details on pcretest tool that you just showed.
    pcretest is a Linux command:
    http://linux.about.com/library/cmd/blcmdl1_pcretest.htm

    It is also available under cygwin ("Get that Linux feeling - on Windows!").

    I searched and found this online regexp tester:
    http://www.regextester.com/

    I tried the regexp from above and with "Preg" option it works.

    > Do I have to use curl command and refer a service with the mentioned xsl to test the expression?
    You may use/modify the stylesheet I attached for PCRE testing on DataPower.

    Hermann.
    Updated on 2014-03-25T03:35:29Z at 2014-03-25T03:35:29Z by iron-man
  • Jaango
    Jaango
    274 Posts

    Re: pcre expression

    ‏2011-01-28T05:54:18Z  
    • HermannSW
    • ‏2011-01-27T20:40:41Z
    Maneesh,

    your last comment did not show all details, here is it again for completeness:
    <pre class="java dw" data-editor-lang="java" data-pbcklang="java" dir="ltr">> Worked with ^(?!127\.0\.0\.1)[0-9.]$ > :) </pre>
    You should put output with special characters inside {code} tags.
    > Also, Do you have any details on pcretest tool that you just showed.
    pcretest is a Linux command:
    http://linux.about.com/library/cmd/blcmdl1_pcretest.htm

    It is also available under cygwin ("Get that Linux feeling - on Windows!").

    I searched and found this online regexp tester:
    http://www.regextester.com/

    I tried the regexp from above and with "Preg" option it works.

    > Do I have to use curl command and refer a service with the mentioned xsl to test the expression?
    You may use/modify the stylesheet I attached for PCRE testing on DataPower.

    Hermann.
    Perfect. Thanks a lot. Yeah, going forward will put the special characters in the {code} tags.