我对正则表达式很陌生,我一直在为找到正确的表达式而苦苦挣扎,如下所示:如果字符串以“n”或“p”开头,我需要得到,为此我有^ (N | p)的。接下来任何三种组合都可能发生,为此我有(组合|组合),之后我问题开始上升。如果“hvt”在之前的条件之后发生,我需要匹配,但如果它只是“hv”而不是“hv”,那么任何子字符串都应匹配。
任何专家都能帮忙吗?
问候
如果我明白你所追求的是什么,正则表达式^[np][fst]combination(?!hv(?!t)).*
将匹配
nfcombinationhvt //match
pscombinationhvt //match
ntcombinationhvt //match
nfcombinationdrums //match
pscombinationguitar //match
ntcombinationkicker //match
nfcombinationhvxxx //no match
pscombinationhvzz //no match
ntcombinationhva //no match
nfcombinationhv //no match
pscombinationhv //no match
ntcombinationhv //no match