Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Regex.IsMatch that simulates Case Statement

Posted on 2005-05-13
Medium Priority
Last Modified: 2008-02-26
Is it possible to code a Regex.IsMatch that returns True if it finds exact matches of multiple values, simulating a Case Statement?  Pseudo code:

// Select Case MyString
// Case MyValue1,MyValue2,MyValue3
if (Regex.IsMatch(MyString,"MyValue1,MyValue2,MyValue3") {
    Console.WriteLine("MyString equals MyValue1 or MyValue2 or MyValue3");
// Case Else
else {
    Console.WriteLine("MyString doesn't equal MyValue1 or MyValue2 or MyValue3");
// End Select
Question by:arichexe
  • 2
LVL 96

Expert Comment

by:Bob Learned
ID: 13998382


Author Comment

ID: 13998806
I'm getting compile errors on the ^ and $ characters:

if (!Regex.IsMatch(MyString,^("val1"|"val2"|"val3")$)
LVL 96

Accepted Solution

Bob Learned earned 500 total points
ID: 13998824
if (!Regex.IsMatch(MyString,@"^(val1|val2|val3)$")


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Screencast - Getting to Know the Pipeline
How can you see what you are working on when you want to see it while you to save a copy? Add a "Save As" icon to the Quick Access Toolbar, or QAT. That way, when you save a copy of a query, form, report, or other object you are modifying, you…
Suggested Courses
Course of the Month15 days, 11 hours left to enroll

580 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question