简体   繁体   中英

Issue with regex (3 capital letters proceeding with 4 numbers)

I have the following code, which should be passing the regex but it isn't, I'm missing something?

if (Regex.IsMatch("ABC1234", "/^[A-Z]{3}[0-9]{4}$"))
        {
            //Pasosed Regex
            Console.WriteLine("Pass");
        }
        else
        {
            Console.WriteLine("No Pass");
        }

Output: "No Pass"

Can Anyone help?

Remove the / from your pattern and it should work.

Console.WriteLine(
    Regex.IsMatch("ABC1234", "^[A-Z]{3}[0-9]{4}$").ToString()
);
// True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM