1

Want to using C# Regex to match string. but always return false. code below

bool isMatch(string preDZ, string matchStr)
{

    string pat = preDZ + "/d{8}";
    Regex reg = new Regex(pat);

    return reg.Match(matchStr).Success;
}

Print(isMatch("AS", "AS00000001"));

but always return false. how to set the pattern to match the string "AS" + 8 length digits?

1 Answer 1

2

Just try something looks like this:

bool isMatch(string preDZ, string matchStr)
{
    string pat = preDZ + @"\d{8}";
    Regex reg = new Regex(pat);

    return reg.Match(matchStr).Success;
}
Sign up to request clarification or add additional context in comments.

2 Comments

modify string pat = preDZ + "\\d{8}";, and it working now.
@KenChu I added @ to string, so it more clearility than "\\"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.