[英]C# regular expression
請在這里提出建議:
我嘗試在C#中做一個正則表達式。 這是文字
E1A: pop(+)
call T
call E1
E1B: return
TA: call F
call T1
我想這樣分割它:
1)
E1A: pop(+)
call T
call E1
2)
E1B: return
3)
TA: call F
call T1
我向后看,但由於。+而無法正常工作
這是我希望工作的結果,但並非如此:
"[A-Z0-9]+[:].+(?=([A-Z0-9]+[:]))"
有誰有更好的想法?
編輯:“ E1A”,“ E1B”,“ TA”正在更改。 唯一相同的是它們由字母和數字組成,后跟“:”
Regex regexObj = new Regex(
@"^ # Start of line
[A-Z0-9]+: # Match identifier
(?: # Match...
(?!^[A-Z0-9]+:) # (unless it's the start of the next identifier)
. # ... any character,
)* # repeat as needed.",
RegexOptions.Singleline | RegexOptions.Multiline | RegexOptions.IgnorePatternWhitespace);
allMatchResults = regexObj.Matches(subjectString);
現在allMatchResults.Count
將包含allMatchResults.Count
的匹配subjectString
,而allMatchResults.Item[i]
將包含第i
個匹配項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.