本文整理汇总了C#中System.Text.RegularExpressions.Regex类的典型用法代码示例。如果您正苦于以下问题:C# System.Text.RegularExpressions.Regex类的具体用法?C# System.Text.RegularExpressions.Regex怎么用?C# System.Text.RegularExpressions.Regex使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
System.Text.RegularExpressions.Regex类属于命名空间,在下文中一共展示了System.Text.RegularExpressions.Regex类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: getByteFromGMKBString
public static long getByteFromGMKBString(String text)
{
long result = 0;
System.Text.RegularExpressions.Regex gbReg = new System.Text.RegularExpressions.Regex(@"(\d+)GB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex kbReg = new System.Text.RegularExpressions.Regex(@"(\d+)KB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex mbReg = new System.Text.RegularExpressions.Regex(@"(\d+)MB", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex bReg = new System.Text.RegularExpressions.Regex(@"(\d+)B", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
if (bReg.IsMatch(text)) {
var m = bReg.Match(text);
result += long.Parse(m.Groups[1].Value);
}
if (kbReg.IsMatch(text)) {
var m = kbReg.Match(text);
result += long.Parse(m.Groups[1].Value) * BaseByte;
}
if (mbReg.IsMatch(text)) {
var m = mbReg.Match(text);
result += long.Parse(m.Groups[1].Value) * BaseByte * BaseByte;
}
if (gbReg.IsMatch(text)) {
var m = gbReg.Match(text);
result += long.Parse(m.Groups[1].Value) * BaseByte * BaseByte * BaseByte;
}
return result;
}
示例2: CleanHTML
/// <summary>
/// 清除HTML代码
/// </summary>
/// <param name="text"></param>
/// <returns></returns>
public static string CleanHTML(string text)
{
var regex = new System.Text.RegularExpressions.Regex(@"(<[a-zA-Z].*?>)|(<[\/][a-zA-Z].*?>)");
var content = regex.Replace(text, string.Empty);
content = content.Replace(" ", " ");
return content;
}
示例3: ConvertToDouble
/// <summary>
/// Handling label_value_numeric
/// </summary>
public static Double ConvertToDouble(string s)
{
try
{
string result = "";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex("[1-9][0-9,.]*");
var arr = reg.Match(s).Value.Split('.');
if (arr.Length == 1)
result = arr[0];
else
result = arr[0] + "." + arr[1];
result = result.Trim('.');
if (String.IsNullOrWhiteSpace(result))
return 0;
return Convert.ToDouble(result);
}
catch (Exception ex)
{
logger.Info("Error occured in ConvertToDouble for label_value_numeric - "+ex.Message);
return 0;
}
}
示例4: RegexTermEnum
public RegexTermEnum(IndexReader reader, Term term)
: base()
{
field = term.Field();
System.String text = term.Text();
pattern = new Pattern(text);
// Find the first regex character position, to find the
// maximum prefix to use for term enumeration
int index = 0;
while (index < text.Length)
{
char c = text[index];
if (!System.Char.IsLetterOrDigit(c))
break;
index++;
}
pre = text.Substring(0, (index) - (0));
SetEnum(reader.Terms(new Term(term.Field(), pre)));
}
示例5: Html2String
/// <summary>
/// Html到文本
/// </summary>
/// <param name="Html"></param>
/// <param name="html"></param>
/// <returns></returns>
public static string Html2String(this HtmlHelper Html, string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[/s/S]+</script *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[/s/S]*script *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[/s/S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[/s/S]+</iframe *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[/s/S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"/<img[^/>]+/>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=javascript: (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", " ");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
return html;
}
示例6: ValidateEmail
public bool ValidateEmail()
{
bool result = true;
try
{
if (txtMailId.Text.Trim() != string.Empty)
{
System.Text.RegularExpressions.Regex rEMail = new System.Text.RegularExpressions.Regex(@"\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*");//^[a-zA-Z][\w\.-]{2,28}[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$
if (txtMailId.Text.Length > 0)
{
if (!rEMail.IsMatch(txtMailId.Text))
{
MessageBox.Show("Invalid Email", "Pharmasoft", MessageBoxButtons.OK, MessageBoxIcon.Information);
result = false;
txtMailId.Focus();
}
}
}
}
catch (Exception ex)
{
MessageBox.Show("SM" + ex.Message, "OpenMiracle", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
return result;
}
示例7: ReplaceSpriteMetaData
private static string ReplaceSpriteMetaData(string metafileText, string oldPrefix, string newPrefix)
{
string spritenamePattern = "(- name: )" + oldPrefix;
var spritenameRegex = new System.Text.RegularExpressions.Regex(spritenamePattern);
string replacementText = "$1" + newPrefix;
return spritenameRegex.Replace(metafileText, replacementText);
}
示例8: GetDefaultDomain
public static string GetDefaultDomain(string tnsNamePath)
{
if (string.IsNullOrEmpty(tnsNamePath)) return "";
if (File.Exists(tnsNamePath) == false) return "";
tnsNamePath = tnsNamePath.ToLower();
if (tnsNamePath.LastIndexOf("tnsnames.ora") < 0) return "";
string sqlnetora = tnsNamePath.Replace("tnsnames.ora", "sqlnet.ora");
if (File.Exists(sqlnetora) == false) return "";
try
{
string sqlnet = File.ReadAllText(sqlnetora);
var reg = new System.Text.RegularExpressions.Regex(@"([#]*)[\t\ ]*NAMES.DEFAULT_DOMAIN\s*=\s*([a-zA-Z0-9_.]+)", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
var m = reg.Match(sqlnet);
if (m.Success)
{
if (m.Groups.Count >= 3)
{
if (m.Groups[1].Value != null && m.Groups[1].Value.IndexOf('#') >= 0) return "";
if (m.Groups[2].Value == null) return "";
return m.Groups[2].Value.Trim().ToUpper();
}
}
return "";
}
catch { return ""; }
}
示例9: CheckStr
/// 过滤html,js,css代码
/// <summary>
/// 过滤html,js,css代码
/// </summary>
/// <param name="html">参数传入</param>
/// <returns></returns>
public static string CheckStr(string html)
{
System.Text.RegularExpressions.Regex regex1 = new System.Text.RegularExpressions.Regex(@"<script[\s\S]+</script. *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex2 = new System.Text.RegularExpressions.Regex(@" href *= *[\s\S]*script. *:", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex3 = new System.Text.RegularExpressions.Regex(@" no[\s\S]*=", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex4 = new System.Text.RegularExpressions.Regex(@"<iframe[\s\S]+</iframe. *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex5 = new System.Text.RegularExpressions.Regex(@"<frameset[\s\S]+</frameset *>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex6 = new System.Text.RegularExpressions.Regex(@"\<img[^\>]+\>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex7 = new System.Text.RegularExpressions.Regex(@"</p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex8 = new System.Text.RegularExpressions.Regex(@"<p>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
System.Text.RegularExpressions.Regex regex9 = new System.Text.RegularExpressions.Regex(@"<[^>]*>", System.Text.RegularExpressions.RegexOptions.IgnoreCase);
html = regex1.Replace(html, ""); //过滤<script></script>标记
html = regex2.Replace(html, ""); //过滤href=java script. (<A>) 属性
html = regex3.Replace(html, " _disibledevent="); //过滤其它控件的on...事件
html = regex4.Replace(html, ""); //过滤iframe
html = regex5.Replace(html, ""); //过滤frameset
html = regex6.Replace(html, ""); //过滤frameset
html = regex7.Replace(html, ""); //过滤frameset
html = regex8.Replace(html, ""); //过滤frameset
html = regex9.Replace(html, "");
html = html.Replace(" ", "");
html = html.Replace("</strong>", "");
html = html.Replace("<strong>", "");
html = html.Replace("'", "'");
return html;
}
示例10: Run
/// <summary>
/// このクラスでの実行すること。
/// </summary>
/// <param name="runChildren"></param>
public override void Run(bool runChildren)
{
System.Text.RegularExpressions.Regex r = new System.Text.RegularExpressions.Regex("<input [^>]*>");
System.Text.RegularExpressions.Regex r2 = new System.Text.RegularExpressions.Regex(@"(\w)*\s*=\s*"+"\"([^\"]*)\"");
var p = this.GetAncestorRawler().OfType<Page>();
if (p.Any() == false)
{
ReportManage.ErrReport(this, "上流にPageがありません");
return;
}
var page = p.First();
List<KeyValue> list = new List<KeyValue>();
foreach (System.Text.RegularExpressions.Match item in r.Matches(GetText()))
{
var dic = GetParameter(item.Value);
if (dic.ContainsKey("type") && dic["type"] == "hidden")
{
if (dic.ContainsKey("name") && dic.ContainsKey("value"))
{
page.AddParameter(dic["name"], dic["value"]);
list.Add(new KeyValue() { Key = dic["name"], Value = dic["value"] });
}
}
}
base.Run(runChildren);
}
示例11: Parse
public static IUnaryOperator Parse(ISyntaxNode parent, ref string Input, IRightValue firstOperand)
{
string temp = Input;
Pattern regExPattern =
"^\\s*" +
new Group("def", "(\\+|-|!|~|\\*|&)");//|\\("+Provider.type+"\\)
System.Text.RegularExpressions.Regex regEx = new System.Text.RegularExpressions.Regex(regExPattern);
System.Text.RegularExpressions.Match match = regEx.Match(Input);
if (!match.Success)
{
Input = temp;
return null;
}
Input = Input.Remove(0, match.Index + match.Length);
string Operator = match.Groups["def"].Value;
switch (Operator)
{
default:
Input = temp;
throw new NotImplementedException();
}
}
示例12: openFileDialog1_FileOk
private void openFileDialog1_FileOk(object sender, CancelEventArgs e)
{
String filePath = openFileDialog1.FileName;
openFileDialog1.InitialDirectory = filePath;
mobiles.Clear();
listBox1.Items.Clear();
if (File.Exists(filePath)){
using (StreamReader sr = File.OpenText(filePath))
{
string s = "";
while ((s = sr.ReadLine()) != null)
{
System.Text.RegularExpressions.Regex rex = new System.Text.RegularExpressions.Regex(@"^\d+$");
if (s.Length == 11&& rex.IsMatch(s))
{
if (!mobiles.Contains(s))
{
mobiles.Add(s);
listBox1.Items.Add(s);
}
}
}
}
}
msgLab.Text = "你将给 " + mobiles.Count + " 个人群发信息,短信字数共计为 " + contentTxt.Text.Length + " 个";
}
示例13: HandleCreateAccount
private static string HandleCreateAccount(HttpServer server, HttpListenerRequest request, Dictionary<string, string> parameters)
{
if (!parameters.ContainsKey("username")) throw new Exception("Missing username.");
if (!parameters.ContainsKey("password")) throw new Exception("Missing password.");
string username = parameters["username"];
string password = parameters["password"];
if (Databases.AccountTable.Count(a => a.Username.ToLower() == username.ToLower()) > 0) return JsonEncode("Username already in use!");
System.Text.RegularExpressions.Regex invalidCharacterRegex = new System.Text.RegularExpressions.Regex("[^a-zA-Z0-9]");
if (invalidCharacterRegex.IsMatch(username)) return JsonEncode("Invalid characters detected in username!");
Random getrandom = new Random();
String token = getrandom.Next(10000000, 99999999).ToString();
AccountEntry entry = new AccountEntry();
entry.Index = Databases.AccountTable.GenerateIndex();
entry.Username = username;
entry.Password = password;
entry.Verifier = "";
entry.Salt = "";
entry.RTW_Points = 0;
entry.IsAdmin = 0;
entry.IsBanned = 0;
entry.InUse = 0;
entry.extrn_login = 0;
entry.CanHostDistrict = 1;
entry.Token = token;
Databases.AccountTable.Add(entry);
Log.Succes("HTTP", "Successfully created account '" + username + "'");
return JsonEncode("Account created!\n\nYour token is: " + token + ".\nCopy and paste given token in \"_rtoken.id\" file and put it in the same folder where your \"APB.exe\" is located.");
}
示例14: NumberRange
public NumberRange(string range)
: this()
{
if (String.IsNullOrEmpty(range))
return;
if (regex == null)
regex = new System.Text.RegularExpressions.Regex("[0-9][0-9]*");
int matchNumber = 1;
foreach (System.Text.RegularExpressions.Match match in regex.Matches(range))
{
switch (matchNumber)
{
case 1:
minimum = maximum = System.Convert.ToInt32(match.Value);
break;
case 2:
maximum = System.Convert.ToInt32(match.Value);
break;
default:
throw new Exception("Invalid number range \"" + range + "\".");
}
matchNumber++;
}
if(matchNumber == 1)
throw new Exception("Invalid number range \"" + range + "\".");
isSet = true;
}
示例15: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
////get the expired cookie
//System.Web.Security.FormsAuthentication.SignOut();
////set the cookie Domain
//HttpCookie lcookie2 = Context.Response.Cookies[System.Web.Security.FormsAuthentication.FormsCookieName];
//lcookie2.Domain = Core.Global.CookieDomain;
OnlineUserBlock.Components.oluMonitor.MemberSignout();
Session.Clear();
if (Request.Cookies["sid"] != null || Request.Cookies["sso"] != null)
{
Response.Cookies["sid"].Expires = DateTime.Now;
Response.Cookies["sso"].Expires = DateTime.Now;//单点登录的Cookie
}
string url = CY.Utility.Common.RequestUtility.GetCookieValue("CurrentUrl");
Response.Cookies["CurrentUrl"].Expires = DateTime.Now;//用户访问过的上个页面地址
System.Text.RegularExpressions.Regex R = new System.Text.RegularExpressions.Regex("(" + url + ")+"); //查找"Abc"
System.Text.RegularExpressions.Match M = R.Match("Logout.aspx"); //设定要查找的字符串
if (M.Index > 0 || url.Length <= 4)
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "logout", "<script type='text/javascript'>window.location.href='Login.aspx';</script>");
}
else
{
Page.ClientScript.RegisterStartupScript(this.GetType(), "logout", "<script type='text/javascript'>window.location.href='" + url + "';</script>");
}
}