Regex怎么用?

walar 2009-04-13 11:22:36
Regex regx;
我应该regx.什么设置他的比对正则表达式呢?
...全文
1682 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
shaw 2010-01-13
  • 打赏
  • 举报
回复
谢谢诶!
huangzhe10 2009-05-25
  • 打赏
  • 举报
回复
正则表达式也太复杂了吧!
中文与英文的啊!再复杂的!
huangzhe10 2009-05-25
  • 打赏
  • 举报
回复
正则表达式也太复杂了吧!
中文与英文的啊!再复杂的!
huangzhe10 2009-05-25
  • 打赏
  • 举报
回复
正则表达式也太复杂了吧!
中文与英文的啊!再复杂的!
十八道胡同 2009-04-13
  • 打赏
  • 举报
回复
学习
wuyq11 2009-04-13
  • 打赏
  • 举报
回复
Regex是从字符窗中查找匹配字符串的应用类。通过Regex,能够非常方便的从一段数据中提取自己所需要的数据信息。

Regex regex = new Regex(@"d+");
Match m = regex.Match("aaa");
Console.WriteLine(m.Value.ToString());
参考
claymore1114 2009-04-13
  • 打赏
  • 举报
回复
引用命名空间 using System.Text.RegularExpressions;
//删除脚本
Htmlstring = Regex.Replace(Htmlstring, @" <script[^>]*?>.*? </script>", "", RegexOptions.IgnoreCase);
cxk106 2009-04-13
  • 打赏
  • 举报
回复
你想说的是:regex.Replace(string,string)?
ljhcy99 2009-04-13
  • 打赏
  • 举报
回复
你先看看msdn 了解下基本内容阿
from911cs 2009-04-13
  • 打赏
  • 举报
回复
不明白,你是要问正则表达式的一般匹配,还是什么啊!
cxk106 2009-04-13
  • 打赏
  • 举报
回复
public static bool IsEnglisCh(string input)
{
Regex regex = new Regex("^[A-Za-z]+$");
return regex.IsMatch(input);
}
teerhu 2009-04-13
  • 打赏
  • 举报
回复
public class PageValidate
{
private static Regex RegNumber = new Regex("^[0-9]+$");
private static Regex RegNumberSign = new Regex("^[+-]?[0-9]+$");
private static Regex RegDecimal = new Regex("^[0-9]+[.]?[0-9]+$");
private static Regex RegDecimalSign = new Regex("^[+-]?[0-9]+[.]?[0-9]+$"); //等价于^[+-]?\d+[.]?\d+$
private static Regex RegEmail = new Regex("^[\\w-]+@[\\w-]+\\.(com|net|org|edu|mil|tv|biz|info)$");//w 英文字母或数字的字符串,和 [a-zA-Z0-9] 语法一样
private static Regex RegCHZN = new Regex("[\u4e00-\u9fa5]");

public PageValidate()
{
}


#region 数字字符串检查

/// <summary>
/// 检查Request查询字符串的键值,是否是数字,最大长度限制
/// </summary>
/// <param name="req">Request</param>
/// <param name="inputKey">Request的键值</param>
/// <param name="maxLen">最大长度</param>
/// <returns>返回Request查询字符串</returns>
public static string FetchInputDigit(System.Web.HttpRequest req, string inputKey, int maxLen)
{
string retVal = string.Empty;
if (inputKey != null && inputKey != string.Empty)
{
retVal = req.QueryString[inputKey];
if (null == retVal)
retVal = req.Form[inputKey];
if (null != retVal)
{
retVal = SqlText(retVal, maxLen);
if (!IsNumber(retVal))
retVal = string.Empty;
}
}
if (retVal == null)
retVal = string.Empty;
return retVal;
}
/// <summary>
/// 是否数字字符串
/// </summary>
/// <param name="inputData">输入字符串</param>
/// <returns></returns>
public static bool IsNumber(string inputData)
{
System.Text.RegularExpressions.Match m = RegNumber.Match(inputData);
return m.Success;
}
/// <summary>
/// 是否数字字符串 可带正负号
/// </summary>
/// <param name="inputData">输入字符串</param>
/// <returns></returns>
public static bool IsNumberSign(string inputData)
{
System.Text.RegularExpressions.Match m = RegNumberSign.Match(inputData);
return m.Success;
}
/// <summary>
/// 是否是浮点数
/// </summary>
/// <param name="inputData">输入字符串</param>
/// <returns></returns>
public static bool IsDecimal(string inputData)
{
System.Text.RegularExpressions.Match m = RegDecimal.Match(inputData);
return m.Success;
}
/// <summary>
/// 是否是浮点数 可带正负号
/// </summary>
/// <param name="inputData">输入字符串</param>
/// <returns></returns>
public static bool IsDecimalSign(string inputData)
{
System.Text.RegularExpressions.Match m = RegDecimalSign.Match(inputData);
return m.Success;
}

#endregion

#region 中文检测

/// <summary>
/// 检测是否有中文字符
/// </summary>
/// <param name="inputData"></param>
/// <returns></returns>
public static bool IsHasCHZN(string inputData)
{
System.Text.RegularExpressions.Match m = RegCHZN.Match(inputData);
return m.Success;
}

#endregion

#region 邮件地址
/// <summary>
/// 是否是浮点数 可带正负号
/// </summary>
/// <param name="inputData">输入字符串</param>
/// <returns></returns>
public static bool IsEmail(string inputData)
{
System.Text.RegularExpressions.Match m = RegEmail.Match(inputData);
return m.Success;
}

#endregion

}
moonshineidolon 2009-04-13
  • 打赏
  • 举报
回复
set regex=new Regexp
regex.Multiline=True
regex.Global=True
regex.IgnoreCase=True
regex.Pattern="(\(\d{3}\)|\d{3}-)?\d{8}"
if regex.Test("83768888") then
Response.Write "匹配"
else
Response.Write "不匹配"
end if

110,538

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧