我正在嘗試使用正則表達式增加版本號,但我似乎無法得到正則表達式的掛起。我正在嘗試讀取和更改字符串中的符號。我到目前爲止的代碼是:使用正則表達式增加版本號
version_file = "AssemblyInfo.cs"
read_file = open(version_file).readlines()
write_file = open(version_file, "w")
r = re.compile(r'(AssemblyFileVersion\s*(\s*"\s*)(\S+))\s*"\s*')
for l in read_file:
m1 = r.match(l)
if m1:
VERSION_ID=map(int,m1.group(2).split("."))
VERSION_ID[2]+=1 # increment version
l = r.sub(r'\g<1>' + '.'.join(['%s' % (v) for v in VERSION_ID]), l)
write_file.write(l)
write_file.close()
我試圖讀取和改變字符串是:
[assembly: AssemblyFileVersion("1.0.0.0")]
我想寫入文件:
[assembly: AssemblyFileVersion("1.0.0.1")]
所以基本上我想增加一個版本號。
任何人都可以幫助我修復我的regualr表達。我似乎無法掌握必須避開符號的正則表達式。
感謝您的任何幫助。
非常感謝,這完美的作品。我真的需要去處理正則表達式。 – chrissygormley 2010-06-29 15:05:46