Pulak Agrawal
Pulak Agrawal

Reputation: 2481

ANT truncate or regex

A novice question:

I have a string (each word separated by a single space):

ABC_01.1_REL_B121001_10_25_2011.2017 ABC_02.1_REL_B121001_10_25_2011.6053 ABC_02.1_REL_B121001_10_25_2011.5643.

I need to select just ABC_01.1_REL_B121001_10_25_2011.2017 using Ant.

The length of AAAA is not fixed but is always separated by a space from the next token. What is the easiest/best way in Ant to do it? Regex, truncate after n characters?

Upvotes: 1

Views: 1838

Answers (2)

FailedDev
FailedDev

Reputation: 26930

Use ant-contrib's property regex :

<propertyregex property="truncated.string"
               input="${input.string}"
               regexp="(.*?)(?:\s.*|$)"
               select="\1"
/>
<echo message="My truncated string : ${truncated.string}"/>

Tested with ant 1.8.2 and ant-contrib.

Edited after OP edited question.

<target name="get-rel-baseline-name" depends="init-property">       
        <exec executable="cleartool" outputproperty="baselinelist">
            <arg value="lsstream"/>
            <arg value="-fmt"/>
            <arg value="&quot;"/>           
            <arg value="%[latest_bls]p"/>
            <arg value="&quot;"/>
            <arg value="stream:${SOURCE_STREAM}@\Res_VOB"/>                     
        </exec>         
        <propertyregex property="RLS_Baseline"
        input="${baselinelist}"                 
        regexp="(.*?)(?:\s.*|$)"
        select="\1"/>
        <echo message="The original list is ${baselinelist}"/>             
        <echo message="${line.separator}Truncated list is ${RLS_Baseline}"/>

gives me the output

[echo] The original list is A_12.1_REL_B121001_10_25_2011.2017 A_12.1_REL_B121001_10_25_2011.6053..... so on for 10 baselines

[echo]
[echo] Truncated list is

Basically it does not select anything with \1.

If I give \0 it selects the whole string of course and the value of RLS_Baseline is same as A_12.1_REL_B121001_10_25_2011.2017 A_12.1_REL_B121001_10_25_2011.6053.....

Reedit after OP's request :

<propertyregex property="truncated.string"
               input="${input.string}"
               regexp="\s*(\b(\w|\.)+\b)"
               select="\1"
/>
<echo message="My truncated string : ${truncated.string}"/>

Upvotes: 4

Pulak Agrawal
Pulak Agrawal

Reputation: 2481

This is what is working for me currently

regexp="\s*(\b(\w|\.)+\b)"

Upvotes: 0

Related Questions