2011-12-27 16 views
7

私はstr1="A sample string"を持っています。 str1sampleが含まれている場合、matchのようなものがecho、それ以外の場合はnot matchingなどが必要です。私はスクリプトに精通していません。私を助けてください。アリ正規表現はif条件で比較する

答えて

10

あなただけのサブが文字列に存在するかどうかを知りたい場合は、ANT-contribのから<if>タスクと一緒に<contains>タスクを使用することができます。文字列内のパターン(正規表現)をスキャンする場合は、<contains>の代わりに<matches>を使用します。

このページの例のためのチェック:またAnt Manual: Condition Tasks

、例:

<if> 
    <contains string="a sample string" substring="sample" /> 
    <then> 
     <echo>match</echo> 
    </then> 
    <else> 
     <echo>not match</echo> 
    </else> 
</if> 
13

あなたが新しいantを使用している場合は、してみてください... 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"/>