Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
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.
Posted
Updated 28-Sep-14 20:32pm
v2
Comments
BillWoodruff 29-Sep-14 2:07am    
This question is not clear. What have you tried so far ? What do you mean by "extract the value:" do you mean whether 'a is true or false.
rahuls1 29-Sep-14 2:19am    
i need variable a,b,c,d ..
string str = Regex.Match(Readline, @"\(([^)]*)\)").Value;
Sinisa Hajnal 29-Sep-14 2:20am    
Also "I need a and b to store in one list". What about c and d? Another list? Two separate lists? Can everything be in the same list with a, b, c, d columns?
rahuls1 29-Sep-14 2:22am    
ya it will be great or diffrent list also ok..
Sinisa Hajnal 29-Sep-14 2:33am    
What would be great? You still haven't answered Bills questions.

Check the below code :

C#
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>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900