需要在c#中正则表达式 [英] need regular expression in c#
本文介绍了需要在c#中正则表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨
i需要使用regual表达式来提取值
(a == b)
或者(a!= b)
即使这样也是
((a == b)&&(c!= d))
比我需要a,b,c,d来存储在列表中。
i需要a和b存储在一个列表中。
解决方案
尝试这个..
http://www.dotnetperls.com/regex -match [ ^ ]
http://www.tutorialspoint.com/csharp/csharp_regular_expressions.htm [ ^ ]
< blockquote>检查以下代码:
string test = Sql == SqlString&& Sql!= OracleStr || A == b&& b!= c&& D == m;
List< string> Variables = new List< ; string>();
MatchCollection Matches = Regex.Matches(test, @ (\ w +) [=!] +(\ w +),RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase);
foreach (匹配ma in 匹配)
{
if (!Variables.Contains(ma。组[ 1 ]。值))
Variables.Add(ma.Groups [ 1 ] .Value);
if (!Variables.Contains(ma.Groups [ 2 ]。值))
Variables.Add(ma.Groups [ 2 ]。值);
} < / string > < / string >
hi
i need regual expression to extract the value
(a==b)
or(a!=b)
even like this also
((a==b)&&(c!=d))
than i need a,b,c,d to store in list.
i need a and b to store in one list.
解决方案
Try this..
http://www.dotnetperls.com/regex-match[^]
http://www.tutorialspoint.com/csharp/csharp_regular_expressions.htm[^]
Check the below code :
string test = "Sql==SqlString && Sql!=OracleStr || A==b&&b!=c&&D==m"; List<string> Variables = new List<string>(); MatchCollection Matches = Regex.Matches(test, @"(\w+)[=!]+(\w+)", RegexOptions.Compiled | RegexOptions.Singleline | RegexOptions.IgnoreCase); foreach (Match ma in Matches) { if (!Variables.Contains(ma.Groups[1].Value)) Variables.Add(ma.Groups[1].Value); if (!Variables.Contains(ma.Groups[2].Value)) Variables.Add(ma.Groups[2].Value); }</string></string>
这篇关于需要在c#中正则表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文