How to pull out a substring in Ant

ant propertyregex
ant regex
ant filterchain
ant string manipulation
ant split string
ant replace text in string
ant trim
ant split property

Is there a way to pull a substring from an Ant property and place that substring into it's own property?

I use scriptdef to create a javascript tag to substring, for exemple:

  <scriptdef name="substring" language="javascript">
     <attribute name="text" />
     <attribute name="start" />
     <attribute name="end" />
     <attribute name="property" />
       var text = attributes.get("text");
       var start = attributes.get("start");
       var end = attributes.get("end") || text.length();
       project.setProperty(attributes.get("property"), text.substring(start, end));
  <target ...>
     <substring text="asdfasdfasdf" start="2" end="10" property="subtext" />
     <echo message="subtext = ${subtext}" />

How to get substring of a string in ANT property, I have a requirement to get a substring out of a string in to ant property. Example string: 1=tibunit-1.4.2.projlib\=. I want to extract the part before . I am a little confused. This statement: String s1 = "banana" is Java syntax, not Ant syntax. Or do you mean that in the Ant script a property gets set and you want to echo out only a substring of that properties string value?

You could try using PropertyRegex from Ant-Contrib.

   <propertyregex property="destinationProperty"
              casesensitive="false" />

Users - How to get substring of a property, Hi, How do I get a substring of a property? Lets say I have a property whose value is "some.value". I want only the characters before the dot i.e. Include Property file in build.xml where the ANT tasks (Step 4) will reside, so it can refer to the property file (Step 2). 4) Create the ANT tasks. The ANT task, myreplace is created within build.xml. This task gets all the keys and iterates through each key in a foreach loop. The ANT-Contrib task that is used to get the keys is propertyselector.

Since I prefer to use vanilla Ant, I use a temporary file. Works everywhere and you can leverage replaceregex to get rid of the part of the string you don't want. Example for munging Git messages:

    <exec executable="git" output="${git.describe.file}" errorproperty="git.error" failonerror="true">
        <arg value="describe"/>
        <arg value="--tags" />
        <arg value="--abbrev=0" />
    <loadfile srcfile="${git.describe.file}" property="git.workspace.specification.version">
           <headfilter lines="1" skip="0"/>
              <replaceregex pattern="\.[0-9]+$" replace="" flags="gi"/>

How to find substring of a string using Ant (Other Build Tools forum , Take a look at the property selector. It uses regular expressions rather than substrings, but you can make a regular expression to represent a� Extract substring in Bash. The syntax is: ## syntax ## ${parameter:offset:length} The substring expansion is a bash feature. It expands to up to length characters of the value of parameter starting at the character specified by offset.

I guess an easy vanilla way to do this is:

<loadresource property="destinationProperty">
        <replaceregex pattern="regexToMatchSubstring" replace="\1" />

Apache Ant – Extract a string from property using regular expression , The Ant-Contrib library is a must have tool if you need to have more control on your build flow. Here is another example on using the� The substring() method extracts the characters from a string, between two specified indices, and returns the new sub string. This method extracts the characters in a string between "start" and "end", not including "end" itself.

I would go with the brute force and write a custom Ant task:

public class SubstringTask extends Task {

    public void execute() throws BuildException {
        String input = getProject().getProperty("oldproperty");
        String output = process(input);
        getProject().setProperty("newproperty", output);

What's left it to implement the String process(String) and add a couple of setters (e.g. for the oldproperty and newproperty values)

How to get substring of a string in ANT property - - Alconcel, i have requirement substring out of string in ant property. example string: i want extract part before .projlib\= , after first = . the result should be: Substring between parentheses. To extract a substring between parentheses (or braces, brackets, slashes, etc.), use the MID and the FIND function in Excel. 1. The formula below is almost perfect. Explanation: the FIND function finds the position of the opening parenthesis. Add 1 to find the start position of the substring.

Conditions Task, The <not> element expects exactly one other condition to be nested into this element, Any of GET , POST , HEAD , OPTIONS , PUT , DELETE and TRACE are valid, subject to protocol restrictions. substring, The string to search for. Yes . If indexEnd is omitted, substring() extracts characters to the end of the string. If indexStart is equal to indexEnd, substring() returns an empty string. If indexStart is greater than indexEnd, then the effect of substring() is as if the two arguments were swapped; See example below.

Properties and PropertyHelpers, For a list of system properties, see the javadoc of System. PropertyHelper$ Delegate marker interface) to take care of discrete tasks such as property setting, getReference( property.substring(prefix.length())); } return o == null ? null : o. It returns the substring starting from the specified index till the end of the given string. Indexes range with 0 to N where N is length of string. The begin index location is inclusive i.e. the result substring will contain the character at index position 'beginIndex' .

How do I get a substring between tags in a String?, In addition, StringUtils also has a method that returns an array of Strings if multiple substrings are found. The SubstringBetweenTest class illustrates that. First, it� On //3 we let Ant do all the tests (which enforced a compile of all tests) without stopping on first failure. Next we apply our work onto Ant sources. Because we haven't modified any, this is a relatively simple step. (Because I have a local Git clone of Ant and usually contribute my work, I work on the local copy just from the beginning.

  • Can you be more specific about what you're trying to do? Why wouldn't it make more sense to define a property to hold the value you're depending on and use it in multiple places? If your Ant properties are changing often enough that you need to programatically react to them, you may be doing something else wrong.
  • Additional note: In case this is done dynamically in a loop, use override="true" to override any previous value.
  • If you're dealing with a property to start with, you can eschew the file by doing something like <loadresource><concat>${} </concat><filterchain><replaceregex pattern="*eek"/></filterchain> </loadresource>
  • Thank you! I used <echo file="version.txt" message="${version}"/> instead of exec and worked perfectly
  • Hi, i got this error: Unable to create javax script engine for ruby
  • Jarod, you need bsf.jar ( and jruby.jar (, see also, note that the link to jruby is wrong on that page.