如果条件,Ant正则表达式比较

Moh*_*igh 7 regex ant string-comparison

我有str1="A sample string".如果str1包含sample,我需要echomatch否则not matching.我不熟悉脚本.请帮我.

Jay*_*yan 14

如果您使用较新的蚂蚁,请尝试... 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"/>
Run Code Online (Sandbox Code Playgroud)


coo*_*fan 12

如果你只是想知道,如果在字符串中存在一个子,你可以使用<contains>连同任务<if>,从任务蚂蚁的contrib.如果要扫描字符串中的模式(正则表达式),请使用<matches>而不是<contains>.

检查此页面中的示例:Ant手册:条件任务

另外,一个例子:

<if>
    <contains string="a sample string" substring="sample" />
    <then>
        <echo>match</echo>
    </then>
    <else>
        <echo>not match</echo>
    </else>
</if>
Run Code Online (Sandbox Code Playgroud)