我有以下代碼匹配特定的字符串,它是一個子一個又一個字符串
// the values for the input and the pattern
// are combinations of R, NR and HR
var input = "NR|HR";
var pattern = "R";
var isMatch = Regex.IsMatch(input, pattern, RegexOptions.IgnoreCase);
這個返回true
因爲NR and HR
包含R
有一些方法我可以做一個精確匹配R
與正則表達式?
你真的需要正則表達式?你爲什麼不簡單地做'var containsR = input.Split('|')。Contains('R')'? –