Why does this regex with no special character match a longer string?

前端 未结 4 1029
有刺的猬
有刺的猬 2021-01-23 00:21

I am using this method to try find a match, in an example:

Regex.Match(\"A2-TS-OIL\", \"TS-OIL\", RegexOptions.IgnoreCase).Success;

I got a tru

4条回答
  •  有刺的猬
    2021-01-23 00:47

    TS-OIL is a substring in your A2-TS-OIL. So, it would generate a match. You have the simplest match possible - literal substring. If you want TS-OIL to not match, you could also try (?!^A2-)(TS-OIL), assuming that you don't want it to start with A2-, but other things might be desired.

提交回复
热议问题