其他問題的啓發在這裏一組字符(我已經接受了非正則表達式的解決方案) c# regex match set of characters in any order only onceC#正則表達式匹配不repeates
但是從@Dmitry埃格羅夫該解決方案是目前更優雅,我仍然努力解決它正確(如果它可以用一個正則表達式來解決) 我得到的最接近的是這一個
^(.|\n)*<\[SG (?!.*(.).*\2)[msbrelft]+\]>(.|\n)*$
文字應符合如下
ID-CFI Location 02h displays sector protection status for the sector selected by the sector address (SA) used in the ID-CFI enter
command. To read the protection status of more than one sector it is necessary to exit the ID ASO and enter the ID ASO using the
new SA. <[SG sbl]>
Page mode read between ID locations other than 02h is supported.
我在C#中使用此檢查
if (!Regex.IsMatch(obj.Object_Text, format.Value))
...
...
在的話,比賽應該是:
- if this exists anywhere in text <[SG sbl]> including over \n or \r\n
- letters should be in this group of letters [msbrelft]
- must be minimum one letter, eg. <[SG s]>
- can be up to all from group, eg. <[SG sbl]>
- must be only one letter (no duplicates), eg. <[SG sbsl]> is NOT good
我不想提取物組,只是驗證所有文字,如果包含< [SG XX。 。]>與先前解釋的規則。
現在我已經上來,將我瘋了,是
^(.|\n)*<\[SG (?!.*(.).*\2)[msbrelft]+\]>(.|\n)*$
不驗證後,如果我的組值得關注的有兩個字母在同一行(無\ r \ n或\ n )。
因此,例如,該作品(還有一個\ n或\ r \ n組後)
ID-CFI Location 02h displays sector protection status for the sector selected by the sector address (SA) used in the ID-CFI enter
command. To read the protection status of more than one sector it is necessary to exit the ID ASO and enter the ID ASO using the
new SA. <[SG sbl]>
Page mode read between ID locations other than 02h is supported.
,這不是(我的組後兩個空格)
ID-CFI Location 02h displays sector protection status for the sector selected by the sector address (SA) used in the ID-CFI enter
command. To read the protection status of more than one sector it is necessary to exit the ID ASO and enter the ID ASO using the
new SA. <[SG sbl]> Page mode read between ID locations other than 02h is supported.
任何幫助將非常感謝! 謝謝。
您是否在尋找有效的''子?像[this](http://regexstorm.net/tester?p=%3c%5c%5bSG%5cs%2b%28%3f!%5bmsbrelft%5d*%28%5bmsbrelft%5d%29%5bmsbrelft%5d* %5C1%29%5bmsbrelft%5D%2B%5D%3E與I =%3C%5bSG + SBL%5D%3E%0D 0A%。%3C%5bSG + SBSL%5D%3E)? –
使用正則表達式的最佳方式是獲取正則表達式結果。然後在正則表達式結果上使用Distinct方法。當沒有重複時,正則表達式結果和不同結果將匹配。 – jdweng