Wednesday, July 16, 2008

VI regex rocks

Still working on internationalizing our product today. I have this list of files that used to only be in English that I need to make sure can be added in all of our translated languages. This issue is that I need to make sure that after I copy these sections for each languages, all of the files have unique names. Enters vi and regular expressions. With this simple regex

:1,$s/Id=".*" Name="\(.*\)" S/Id="En\1" Name="\1" S/

I turned
<File Id="file714" Name="ACC_NCDR.mod" Source="$(var.PCodePath)\Modules\ACC_NCDR.mod" />
into
<File Id="EnACC_NCDR.mod" Name="ACC_NCDR.mod" Source="$(var.PCodePath)\Modules\ACC_NCDR.mod" />

The interesting par is the \(.*\). That is remembered as the first expression and the matched value is then inserted when you use \1. In perl , they are called named expressions.

No comments: