Reputation: 129
I'm using replaceregexp to replace a particular match in files. Whenever there are multiple matches in a single line it is only replacing the last instance of the line.
Eg:
Input:
f1.lblTest.text != null && f1.lblTest.text != ""
Reg EX:
<replaceregexp file="mod1.js" match="(.*)f1(\.|\[")lblTest(\.|"\]|\[")(.*)" replace="\1f1\2lblTestNew\3\4 \\/\\/Modified" flags="g">
Expected Output:
f1.lblTestNew.text != null && f1.lblTestNew.text != "" //Modified
Actual Output:
f1.lblTest.text != null && f1.lblTestNew.text != "" //Modified
With this <replaceregexp file="mod1.js" match="f1(\.|\[")$lblTest(\.|"\]|\[")" replace="f1\1lblTestNew\2 \\/\\/Modified" flags="g"> I'm getting the below output
f1.lblTestNew. //Modifiedtext != null && f1.lblTestNew. //Modifiedtext != "".
With this <replaceregexp file="mod1.js" match="f1(\.|\[")$lblTest(\.|"\]|\[")" replace="f1\1lblTestNew\2" flags="g"> I'm getting the below output
f1.lblTestNew.text != null && f1.lblTestNew.text != "" This is ok but I really wanted a comment that lets the users know that this is modified and if they want they can modify again.
Please suggest any solutions.
Note:I tried g,m,s flags with and without 'byline' already and they didn't work.
Upvotes: 1
Views: 376
Reputation: 626896
Since you have no conditional replacement pattern support in Ant replaceregexp
, there is only one possible solution involving 2 steps:
<replaceregexp file="mod1.js" match="f1(\.|\[")$lblTest(\.|"\]|\[")" replace="f1\1lblTestNew\2" flags="g">
to replace all the lblTest
with lblTestNew
texts//Modified
substring to the end of the strings, say, with <replaceregexp file="mod1.js" match="(.*f1(\.|\[")lblTestNew(\.|"\]|\[").*)" replace="\1 // Modified">
.Upvotes: 1