regex - ANT Script - replaceregexp with non-matching groups -
i trying use replaceregexp
search , replace copyright symbol , garbage characters on multiple files ones have date in 2000 range, decided use non-capturing group match number after copyright symbol , replace copyright symbol. reason still replaces symbol , number.
for example, match:
© 2007 mail services bla bla bla
and expected result be:
c 2007 mail services bla bla bla
but get:
c bla bla bla
here code:
<replaceregexp match="${match.exp}" replace="${replace.str}" byline="true"> <fileset dir="${parent.dir}"> <include name="**/*.js"/> <include name="**/*.jsp"/> <include name="**/*.xml"/> <include name="**/*.properties"/> <include name="**/*.css"/> <include name="**/*.java"/> <!-- excluding files --> <exclude name="**/yu.js"/> <exclude name="**/jsmenu.js"/> <exclude name="**/jquerytimerpack.js."/> <exclude name="**/jqu.js"/> <exclude name="**/jqui.js"/> <exclude name="**/am.properties"/> </fileset> </replaceregexp>
the regex i'm using is:
(?:\s*)(©|�|©)(?:\s*20\d\d,\smail services)
the non-capturing group still consumed , replaced, isn't "captured" in sense characters matched pattern in group aren't stored you. (see answer: regex non-capturing group capturing)
instead should capture groups , use them rebuild desired string.
for example, if you're regex (?:\s*)(©|�|©)(?:\s*20\d\d,\smail services)
, try instead using (\s*)(©|�|©)(\s*20\d\d,\smail services)
, replace string of \1c\2
. i'm not sure if comma in last group intended, since wouldn't match examples provided.
Comments
Post a Comment