0

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. :)

1
Contributor
1
Reply
3
Views
5 Years
Discussion Span
Last Post by saad749
0

The Problem is with this part :

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

Changing it to

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

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.