I have this Regular Expression in C#:

    Regex myRegex = new Regex(@"^[a-zA-Z]{1}\s(! | && | \|\| | -> | <->){1}\s[a-zA-Z]{1}$");
    if (myRegex.IsMatch(expression))
    {
        validated = true;
    }
    else
    {
        validated = false;
    }

and I would like to match the following types of Strings:

A && B
A -> B
A || B

The Problem is it is evaluating to false. Any Insight on why it is failing and how it can be corrected will be highly apreciated. :)

The Problem is with this part :

(! | && | \|\| | -> | <->)

Changing it to

(!|&&|\|\||->|<->)

Solves it. White Spaces are s important in Regex; had Not the idea :P

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.