获取正则表达式的字符串 [英] Get the string with regular expressions

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

问题描述

我想获取像TestUploads(1).xls或TestUploads(2).xls等文件名。我使用正则表达式来表示数字。



我尝试下面的代码,但它不起作用。

请任何一个帮助。



  if (Regex.IsMatch(FileUpload.FileName,  TestUploads(^ [0 -9] $)。xls,RegexOptions.IgnoreCase))
{
// 我的代码

}

解决方案

)。xls ,RegexOptions.IgnoreCase))
{
// 我的代码

}


改为尝试:

  if (Regex.IsMatch(Fi leUpload.FileName,  ^ TestUploads \([0-9] + \)\ xls 

,RegexOptions.IgnoreCase))
{
// 我的代码
}



问题是'^'和'


I want to get the file names like TestUploads(1).xls or TestUploads(2).xls etc. Im used the regular expressions for number .

I tried below code but it's not working.
Please any one help.

if (Regex.IsMatch(FileUpload.FileName, "TestUploads(^[0-9]$).xls", RegexOptions.IgnoreCase))
               {
                     // My Code

               }

解决方案

).xls", RegexOptions.IgnoreCase)) { // My Code }


Try that instead:

if (Regex.IsMatch(FileUpload.FileName, "^TestUploads\([0-9]+\)\.xls


", RegexOptions.IgnoreCase)) { // My Code }


The problem was the '^' and '


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

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