This seems like it should be simple: Using an Ant task, can I use replaceregexp to replace all of certain repeated characters, only in certain strings in files?
File contents:
Blah blah blah <ac:link> words_with_underscores_to_turn_to_spaces</link>
Blah blah blah Blah blah blah Blah blah blah Blah blah blah
Words_with_underscores_that_I_want_to_keep. Blah blah blah Blah blah blah.
Result wanted is:
Blah blah blah <ac:link> words with underscores to turn to spaces</link>
Blah blah blah Blah blah blah Blah blah blah Blah blah blah
Words_with_underscores_that_I_want_to_keep. Blah blah blah Blah blah blah.
I can use replaceregexp to match <ac:link.*?/link> and limit the replacements to only within those strings, but in that case how do I tell it to replace all underscores that it finds inside that string, no matter where they fall? The lines with underscores aren't always the same number of words.
I also tried a copy task approach, like this:
<copy todir=".\test_output">
<filterchain>
<tokenfilter>
<containsregex pattern="(ac:link.*?link)" flags="gi"/>
<replacestring from="_" to=" "/>
</tokenfilter>
</filterchain>
<fileset dir=".\underscore_test_output" includes="**/*.txt"/>
</copy>
That replaces the underscores with spaces in the links and moves the links into a new file, but it excludes the rest of the source file, since I only matched the links. Any ideas?