471,627 Members | 1,505 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 software developers and data experts.

Help ! regex problem?

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! ");
}
Nov 28 '05 #1
2 1220
roopeman wrote:
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:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2
Nov 28 '05 #2
Thanks! it 's work well under your help !

"Lasse Vågsæther Karlsen" wrote:
roopeman wrote:
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:la***@vkarlsen.no
PGP KeyID: 0x2A42A1C2

Nov 29 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

5 posts views Thread by Bill Cohagan | last post: by
8 posts views Thread by Johnny | last post: by
8 posts views Thread by Bibe | last post: by
2 posts views Thread by Martin Hart | last post: by
9 posts views Thread by jmchadha | last post: by
4 posts views Thread by MooMaster | last post: by
2 posts views Thread by garyusenet | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.