[英]Regular expression match substring
我試圖創建一個正則表達式來提取所有匹配的內容:
[aA-zZ]{2}[0-9]{5}
問題是當我有例如時,我想從匹配中排除。 ABCD12345678
誰能幫我解決這個問題?
EDIT1:我正在字符串中查找兩個字母和五個數字,但是當我擁有ABCD12345678之類的字符串時,我想從匹配中排除,因為當我使用上述正則表達式時,它將返回CD12345。
EDIT2:我沒有檢查所有內容,但我想我找到了答案:
WHEN field is null then field WHEN fnRegExMatch(field, '[a-zA-Z]{2}[0-9]{5}') = 'N/A' THEN field WHEN field like '%[^az][az][az][0-9][0-9][0-9][0-9][0-9][^0-9]%' or field like '[az][az][0-9][0-9][0-9][0-9][0-9][^0-9]%' THEN fnRegExMatch(field, '[a-zA-Z]{2}[0-9]{5}') ELSE field
這將是代碼以及用法示例。
public static Regex regex = new Regex(
"\\b[a-zA-Z]{2}\\d{5}\\b",
RegexOptions.CultureInvariant
| RegexOptions.Compiled
);
//// Replace the matched text in the InputText using the replacement pattern
// string result = regex.Replace(InputText,regexReplace);
//// Split the InputText wherever the regex matches
// string[] results = regex.Split(InputText);
//// Capture the first Match, if any, in the InputText
// Match m = regex.Match(InputText);
//// Capture all Matches in the InputText
// MatchCollection ms = regex.Matches(InputText);
//// Test to see if there is a match in the InputText
// bool IsMatch = regex.IsMatch(InputText);
//// Get the names of all the named and numbered capture groups
// string[] GroupNames = regex.GetGroupNames();
//// Get the numbers of all the named and numbered capture groups
// int[] GroupNumbers = regex.GetGroupNumbers();
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.