regex - Replace string in file using VB.net - case insensitive -


given following partial file example :

<sellgrey>true</sellgrey> <sellwhite>false</sellwhite> <sellgreen>false</sellgreen> <sellblue>false</sellblue> 

what best method case-insensitive search , replace, while keeping proper case on output.

for example:

<sellgrey>true</sellgrey> 

or

<sellgrey>true</sellgrey> 

would searching for, replacement, :

<sellgrey>false</sellgrey> 

lastly, please not hung on "tags" file malformed xml reading/writing xml bugger things up. please @ strings -- case-insensitive string search , replace, on line line basis.

thanks in advance.

since didn't provide detail tags, used dictionary proper casing.

dim input string = "<sellgrey>true</sellgrey>" dim pattern string = "<(?<tag>.+)>(?<value>(true|false))</.+>"  'building dictionary specify how proper case dim tagformatter new dictionary(of string, string) tagformatter.add("sellgrey", "shellgrey") tagformatter.add("sellwhite", "sellwhite") tagformatter.add("sellgreen", "sellgreen") tagformatter.add("sellblue", "sellblue")  'build new string using lambda dim result = regex.replace(input, pattern, _     function(m) string.format("<{0}>{1}</{0}>", _         tagformatter(m.groups("tag").value.tolower), _         if(m.groups("value").value = "true", "true", "false")), _     regexoptions.ignorecase) 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -