Given this regular expression: \"^[0-9]*\\s*(lbs|kg|kgs)$\"
how do I make it case insensitive? I am trying to use this in a .net regular expression validator,
Use RegEx Options.
Regex regExInsensitive = new Regex(@"^[0-9]\s(lbs|kg|kgs)$", RegexOptions.IgnoreCase);
In other languages you can usually specify a RegEx modifier after the end of the Reg Ex; the 'case insensitive' modifier is 'i':
In Perl:
if($var =~ /^[0-9]\s(lbs|kg|kgs)$/i) { # the /i means case insensitive
# ...
}
In PHP:
if(preg_match("/^[0-9]\s(lbs|kg|kgs)$/i", $var)) {
// ...
}