I need to replace a string in a html page.
But I can't get my regexp to find the string.
I have this line:
<span class="foobar">Random text</span>
And I want to change it to this instead:
<span class="foobar">New text</span>
I have tried various variants of this example without match.
<replace file="${install.path}\app_data\Header.htm">
<replacefilter token="foobar">.*" value="foobar"> New text </span>" />
</replace>
What am I missing? When I test the regex in a regex tool it looks fine.
And just as I had posted this, I found the answer:
<replaceregexp match="foobar">(.*)<" replace=foobar"> New text <">
<fileset dir="${install.path}\app_data" includes="Header.htm"/>
</replaceregexp>
Related
Full String: C:\Shrijeet\BW-AUTOMATION-PROJECT\Deploy\CheckedOutproject\TestMaven\testsrv-system\testsrv-esb\src\main\bw-testsrv-esb\deployment\bw-testsrv-esb.archive
I would like to capture only below ant property:
C:\Shrijeet\BW-AUTOMATION-PROJECT\Deploy\CheckedOutproject\TestMaven\testsrv-system\testsrv-esb\src\main\bw-testsrv-esb\
Please can you help with regular expression for this.I tried but i am not able to correctly extract it.
Thanks
I got my answer after some trials.
regexp="(.\)(.\)" will solve my purpose
<propertyregex property="app_project_path" override="true" input="${app_ear_archive}" regexp="(.*\\)(.*\\)" select="\1" />
I tried to use ants loadproperties with expandproperties:
This works for simple text properties but i get weird results when a property contains a windows path.
<property name="myAntFile" value="${ant.file}" />
<loadproperties srcFile="my.properties">
<filterchain>
<expandproperties />
</filterchain>
</loadproperties>
<echo message="$${external} = ${external}" />
the properties file looks like this:
external=${myAntFile}
the result is:
Buildfile: C:\projects\trunk\build.xml
...
[echo] ${external} = C:projects\trunkbuild.xml
I know that for properties files there are escape rules for backslashes and special whitespace characters. However i dont see how i can translate the buildscripts properties to that special meaning.
Anyone has a idea how to solve that or is this a ant bug (maybe the expandproperties chain should get a additional property for escaping when used in property file contexts?)?
With ant you can use a forward slash / as the path separator when defining paths, even on Windows: C:/projects/trunk/build.xml
If ${ant.file} returns the path using backslashes, convert this path first before you load the properties file.
Unfortunately I haven't yet found the definitive way to convert paths from C:\a\path to C:/a/path and back. Supposedly pathconvert can do the trick...
<pathconvert targetos="unix" property="myAntFile.withForwardSlashes">
<path location="${myAntFile}"/>
</pathconvert>
... but it confuses relative and absolute paths and I couldn't make it work while testing this on my OS X machine.
I want to write a code in such a way that I will remove platform from first 3 lines and then take only the platform name and I will suffix that with installer-zip.${platform_name}.
platform.win-x86=true
platform.win-x64=true
platform.unix=false
installer-zip.win-x86=E:\abc.jar
installer-zip.win-x64=E:\def.jar
Now if the selected item is win-x86 then printing installer-zip.${platform_name} should give me E:\abc.jar. I tried ${installer-zip.${platform_name}} and many other things but they are not working
You cannot do this with regular ant, but you can do this with ant-contrib.
In particular, there is a contrib task property-regex.
So something like:
<propertyregex property="$newProperty"
input="$oldProperty"
regexp="^platform\.(,*)$"
select="\1"
casesensitive="false" />
EDIT: and then...
<property name=desiredProperty value="installer-zip.${newProperty}" />
That should give you enough to work out the exact solution you're looking for...
All I need is to create a file that contains a file names' list (separated by '\r\n' or '\n' depending on the OS) in a certain folder. For some reason, the code below doesn't work:
<fileset id="my_files" dir="./resource">
<include name="*.js" />
</fileset>
<pathconvert property="my_files_list" refid="my_files" pathsep="\r\n" />
<echo message="${my_files_list}" file="my_files_list.txt"/>
I am getting the files' list, separate by a string that includes four characters '\r\n' literally. First, I would like them to convert into the real (whitespace) newline, second, I would like them to have an OS-dependent delimiter.
Please advice
You should use the standard Ant line.separator property, rather than hard-coding it to \r\n. This is also more likely to work, rather than being mangled by Ant, as seems to be happening here.
So try this:
<pathconvert property="my_files_list" refid="my_files" pathsep="${line.separator}" />
I have a property defined in one of my property files:
<entry key="build" default="0" type="int" operation="+" value="1" />
I read this property using:
<replacefilter token="#build#" property="build_num" />
Once this number gets bigger than 999, thousand separator commas start appearing, like this:
1,001
1,562
Is there a way to get rid of those commas?
(I use build to generate a file name, and don't really want to see any commas in there).
You can prevent thousand separators from being used by adding a pattern to the entry:
<entry key="build" default="0" type="int" operation="+" value="1" pattern="0" />
Note that you'll probably need to manually remove the commas one-time before running this - else your build numbers will reset, with the comma and subsequent digits being discarded. (So 1,325 -> 2 and 4,111 -> 5 and so on.)
Figured ###0 would have worked, but it didn't. Since the project is already making extensive use of ant-contrib, it wasn't difficult to add the regex solution Aaron suggested.
<propertyregex property="build" input="${build}" regexp="," replace="" global="true" override="true"/>