Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Ant regex compare in if condition

I have str1="A sample string". If the str1 contains sample, I need to echo something like match and otherwise not matching. I am not familiar with ant scripts. Please help me.

like image 938
Mohamed Saligh Avatar asked Dec 27 '11 03:12

Mohamed Saligh


2 Answers

If you are using newer ant, try... http://ant.apache.org/manual/Tasks/conditions.html

<condition property="legal-password">
  <matches pattern="[1-9]" string="${user-input}"/>
</condition>
<fail message="Your password should at least contain one number"
      unless="legal-password"/>
like image 138
Jayan Avatar answered Nov 13 '22 09:11

Jayan


If you just want to know if a substring exists in the string, you can use <contains> task together with <if> task from ant-contrib. If you want to scan for a pattern (a regexp) in a string, use <matches> instead of <contains>.

Check for examples in this page: Ant Manual: Condition Tasks

Also, a example:

<if>
    <contains string="a sample string" substring="sample" />
    <then>
        <echo>match</echo>
    </then>
    <else>
        <echo>not match</echo>
    </else>
</if>
like image 42
Dante WWWW Avatar answered Nov 13 '22 10:11

Dante WWWW