Use the following regex : ^(\w+?)\s*=\s*(ON|OFF)\s*$
Match m=Regex.Match("mySwitch = ON",@"^(\w+?)\s*=\s*(ON|OFF)\s*$");
MessageBox.Show("switchname = "+m.Groups[1]);
MessageBox.Show("switch = "+m.Groups[2]);
Hope it helps,
Ludovic SOEUR.
"James" <ja********@hotmail.com> a écrit dans le message de
news:%2***************@tk2msftngp13.phx.gbl...
User has a input as "SwitchName = ON" or "SwitchName = OFF", how to use C#
Regex to get SwitchName and the value?
Regex.Match(line, @"(\S+) = {ON|OFF}") does not work.