好的Reg Reg专家,我对regex不太满意,希望能有所帮助。我有一个正则表达式,我一生都无法弄清楚。我正在寻找创建一个符合以下条件的正则表达式:
以“ PA”开头(ingore情况)
以数字结尾
长度为8个字符(忽略任何尾随空白)
或
以“ WN”(ingore大小写)开头
以数字结尾
长达10个字符(忽略任何尾随空白)
答案 0 :(得分:1)
//Trim the whitespace off the ends of your string per requirement
yourString = yourString.Trim();
//Declare regex, the pattern tells it to look for any 7 letter word
//which starts with PA and ends with a digit and is 7 characters long
//OR a word which starts with WN and ends with a digit and is 10 characters long.
Regex regex = new Regex(^PA.+\d${7})|(^WN.+\d${10});
//Set the regex option to ignore case
RegexOptions options = RegexOptions.IgnoreCase;
//Get the match collection by passing your string, the regex pattern and
//the regex options
MatchCollection matches = regex.Matches(yourString, regex, options);
//Do something with captured text