正規表現が必要な場合は、これについての私の見解を次に示します。
^ # match start of string
(?=.*a(?:,|$)) # assert it matches a followed by a comma or end-of-str
(?=.*b(?:,|$)) # assert it matches b followed by a comma or end-of-str
(?=.*c(?:,|$)) # assert it matches c followed by a comma or end-of-str
(?:(?:a|b|c)(?:,|$))* # match a, b or c followed by a comma or end-of-str
$ # match end of string
を見つけた場合は.*
、アサーションを保持しますが、正規表現の最後の部分を変更して、すべてに一致するようにします。2番目の例:
^ # match start of string
(?=.*a(?:,|$)) # assert it matches a followed by a comma or end-of-str
(?=.*b(?:,|$)) # assert it matches b followed by a comma or end-of-str
(?:[^,]*(,|$))* # match anything followed by a comma or end-of-str
$ # match end of string
もちろん、正規表現を生成するために文字列を解析する必要があります。この時点で、私は率直に言って、従来のコード(おそらくそれも高速です)を使用することを好みます。例:(擬似コード):
setRequired = Set(csvRequired.Split(','))
setActual = Set(input.Split(','))
if (setActual.Equals(setRequired)))
{
// passed
}
アスタリスクを見つけた場合は、アスタリスクを削除して、代わりにsetRequired
使用してください.Contains
Equals