Help ! regex problem?

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

any problem of the regex? the code as below is not working ! if just one
keyword,such as "Microsoft.*", it 's work well , anybody can help me ,Thanks!
using System.Text.RegularExpressions;

Regex r = new Regex("[Microsoft.*][KingSoft.*][Symantec.*][Oracle.*]");

if (r.IsMatch(strCoName))
{
Console.WriteLine("You are using Standard software");
}
else
{
Console.WriteLine("Hello,We are watching you! please do not enjoy games
in work time! ");
}
 
roopeman said:
any problem of the regex? the code as below is not working ! if just one
keyword,such as "Microsoft.*", it 's work well , anybody can help me ,Thanks!
using System.Text.RegularExpressions;

Regex r = new Regex("[Microsoft.*][KingSoft.*][Symantec.*][Oracle.*]");
<snip>

[...] in regular expressions specify a character class, where [abc]
matches 1 letter only, which can be one of a, b or c.

In other words: [Microsoft.*] would match uppercase M, lowercase i, c,
r, o, s, f, t, a dot, or an asterix (ie. one of those, not all of them
together). Your regular expression is thus 4 characters long, where the
first character can be one of "Microsft.*" (o appears twice), the next
is one of "KingSoft.*", etc. A valid match could be "MKSO" or "M.cl" etc.

If your goal is to match: Microsoft, or Kingsoft, or Symantec, or
Oracle, any of those followed by anything else, the correct regex
expression would be:

"(Microsoft|Kingsoft|Symantec|Oracle).*"

Hope that helps.
 
Thanks! it 's work well under your help !

Lasse Vågsæther Karlsen said:
roopeman said:
any problem of the regex? the code as below is not working ! if just one
keyword,such as "Microsoft.*", it 's work well , anybody can help me ,Thanks!
using System.Text.RegularExpressions;

Regex r = new Regex("[Microsoft.*][KingSoft.*][Symantec.*][Oracle.*]");
<snip>

[...] in regular expressions specify a character class, where [abc]
matches 1 letter only, which can be one of a, b or c.

In other words: [Microsoft.*] would match uppercase M, lowercase i, c,
r, o, s, f, t, a dot, or an asterix (ie. one of those, not all of them
together). Your regular expression is thus 4 characters long, where the
first character can be one of "Microsft.*" (o appears twice), the next
is one of "KingSoft.*", etc. A valid match could be "MKSO" or "M.cl" etc.

If your goal is to match: Microsoft, or Kingsoft, or Symantec, or
Oracle, any of those followed by anything else, the correct regex
expression would be:

"(Microsoft|Kingsoft|Symantec|Oracle).*"

Hope that helps.

--
Lasse Vågsæther Karlsen
http://usinglvkblog.blogspot.com/
mailto:[email protected]
PGP KeyID: 0x2A42A1C2
 
Back
Top