The
Replace
method of
System.Text.RegularExpressions.Regex
class explained here
http://msdn.microsoft.com/en-US/library/taz3ak2f%28v=vs.80%29[
^] can be used for this purpose using the pattern
(?<=foobar\s*=\s*)([^=.]+)(?=\s*\.)
which matches a word if it is preceded by
foobar=
and followed by
.
even when there is white space between foobar & =, = & the required word, required word & . This pattern can be tested here
http://regexhero.net/tester/[
^].
To replace other combinations use variables for
foobar
and the
replace string
.
Dim fileText as String = System.IO.File.ReadAllText(fileName)
Dim modifiedText as String = System.Text.RegularExpressions.Regex.Replace( _
fileText,"(?<=foobar\s*=\s*)([^=.]+)(?=\s*\.)","5000", RegexOptions.IgnoreCase | RegexOptions.CultureInvariant)