使用正则表达式搜索字符串 [英] Search Strings Using Regular Expressions

查看:111
本文介绍了使用正则表达式搜索字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



我有小问题,



Hi Friends ,

I Have Small Problem ,

string sample1 = "AK12-13/000000029024";
            string Patten1 = "^\\[A-Za-z]{2}-\\d{2}/\\d{12}$";
            System.Text.RegularExpressions.Match match1 = System.Text.RegularExpressions.Regex.Match(sample1, Patten1, System.Text.RegularExpressions.RegexOptions.IgnoreCase);
            if (!match1.Success)
            {
                MessageBox.Show("Please enter a valid  Patten.", "TEST", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                return;
            }





但它不起作用,任何一个Plz帮助

Condisions:



•前两位必须是字母AK

•其次,第五个字符必须是 -
•第三,第8个字符必须是/

•最后在第8个位置之后的最后12个字符必须是数字。



But its not working , Any one Plz to Help
Condisions:

• The first two digits have to be Alphabets "AK"
• Secondly, the 5th character has to be a "-"
• Thirdly, the 8th character has to be a "/"
• Finally the last 12 characters after the 8th place onwards have to be numeric.

推荐答案

;
System.Text.RegularExpressions.Match match1 = System.Text.RegularExpressions.Regex.Match(sample1,Patten1,System.Text.RegularExpressions.RegexOptions。 IgnoreCase);
if (!match1.Success)
{
MessageBox.Show( 请输入有效的Patten。 TEST,MessageBoxButtons.OK,MessageBoxIcon 。警告);

return ;
}
"; System.Text.RegularExpressions.Match match1 = System.Text.RegularExpressions.Regex.Match(sample1, Patten1, System.Text.RegularExpressions.RegexOptions.IgnoreCase); if (!match1.Success) { MessageBox.Show("Please enter a valid Patten.", "TEST", MessageBoxButtons.OK, MessageBoxIcon.Warning); return; }





但它不起作用,任何一个Plz帮助

Condisions:



•前两位必须是字母AK

•其次,第五个字符必须是 -
•第三,第8个字符必须是/

•最后,第8个字母后面的最后12个字符必须是数字。



But its not working , Any one Plz to Help
Condisions:

• The first two digits have to be Alphabets "AK"
• Secondly, the 5th character has to be a "-"
• Thirdly, the 8th character has to be a "/"
• Finally the last 12 characters after the 8th place onwards have to be numeric.






试试这个 Patten1 变量:

Hi,

Try this as Patten1 variable:
string Patten1 = "^AK.{2}-.{2}/[0-9]{12}


;



希望这会有所帮助。


Hope this helps.


这篇关于使用正则表达式搜索字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆