Firstly, I am looking for something different from this:
My purpose is modify the
"fillColor="#242838"
with fillColor="mycolor"
However, the hex color in this statement can be anything like
"fillColor="#221231"
or "fillColor="#213123"
So how can I find & edit the text using windows batch file.
Edit: I have tried JREPL.BAT regular expression find/replace utility tool for this.
jrepl "android:fillColor=(.*?)" "fillColor="mycolor" /x /f myfile.xml /o -
However, escaping from "
doesn't work in this line.
I have already tried ""
, \"
, ^"
They don't help me to escape "
character.
The task can be done with JREPL.BAT for example with using following command line:
jrepl.bat "(android:fillColor=\x22#)[0-9A-Fa-f]+" "$1FF0000" /f myfile.xml /o -
Explanation of search string:
(
...)
... marking group. The string found by this group is back-referenced in the replace string with the expression $1
.
\x22
... double quote character specified with its hexadecimal code value.
[0-9A-Fa-f]+
... find any hexadecimal digit one or more times.
All other characters in search expression are literal interpreted characters to find in file.
Explanation of replace string:
$1
... back-reference for the fixed string found by the marking group in search regular expression.
FF0000
... new color value which is here red (RGB).
It is necessary for this replace task to use a marking group as JREPL.BAT is using jscript which does not support look-behind to match just the color value to replace in right context.
This command line must be called with command CALL when used within a batch file:
call jrepl.bat "(android:fillColor=\x22#)[0-9A-Fa-f]+" "$1FF0000" /f myfile.xml /o -