Hello,
Kindly help me i am stuck in the following expression...
string strTest = " (!(2VH_AKTIVLENKUNG_UND_HSR) + !(ALLRAD) + (B47D20 + G011, B47D20 + G012, B48B20 + G011, B48B20 + G012, B57D30 + G011, B57D30 + G012, B58B30 + G011, B58B30 + G012, G011 + N63B40, G012 + N63B40,)";
foreach(string s in Regex.Split(strTest, r))
{
Console.WriteLine(s);
}
I am using the above expression kindly correct to make the above expression work
Expected Output:
2VH_AKTIVLENKUNG_UND_HSR
ALLRAD
B47D20 + G011
B47D20 + G012
B48B20 + G011
B48B20 + G012
B57D30+ G011
B57D30+ G011
B57D30+ G012
B58B30 + G011
B58B30 + G012
G011 + N63B40
G012 + N63B40
VulpesPosted Mar 24, 2014, 12:58 PM
str2 is particularly difficult as the two last strings you want aren't even sub-strings of str2. They will therefore have to be manufactured from captured groups or in some other 'ad hoc' way.
I can try and come up with something that deals with str2 if you like but I thought I'd better warn you first that it won't be able to deal with str1 as well.
Software does exist which can generate regular expressions. Check out this thread for example:
http://stackoverflow.com/questions/910220/any-good-regular-expression-creator-software-or-online-tools-to-create-regular-e
but, frankly, I'll be very surprised if you can generate something here as you can't really define a pattern which the software can work from.
My own view is that it's better to learn the principles of regex and come up with your own expressions as at least you'll understand what you've done and be able to tweak it to deal with variations in the pattern.
sampath mekaPosted Mar 24, 2014, 3:26 AM
VulpesPosted Mar 23, 2014, 10:07 AM
The output should be:
sampath mekaPosted Mar 23, 2014, 6:08 AM
Sorry i typed my expected output wrong so plz correct the expression
string strTest = " (!(2VH_AKTIVLENKUNG_UND_HSR) + !(ALLRAD) + (B47D20 + G011, B47D20
+ G012, B48B20 + G011, B48B20 + G012, B57D30 + G011, B57D30 + G012, B58B30 + G011,
B58B30 + G012, G011 + N63B40, G012 + N63B40,)";
string r = @"(?((?=.*\)))(?<=\)), |, )";
foreach(string s in Regex.Split(strTest, r))
{
Console.WriteLine(s);
}
Expected Output:
!(2VH_AKTIVLENKUNG_UND_HSR)
!(ALLRAD)
B47D20 + G011
B47D20 + G012
B48B20 + G011
B48B20 + G012
B57D30+ G011
B57D30+ G012
B58B30+ G011
B58B30+ G012
G011 + N63B40
G012 + N63B40
VulpesPosted Mar 12, 2014, 7:06 AM