TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
jithendra pasala
NA
53
37.3k
Regular Expressions as Typical
Apr 29 2014 3:43 AM
Hello All,
I want to break the string by using the Regular Expression:
String:"(G011 + !(2VR_2_ACHS_LUFTFEDERUNG, 2VS_MASTERPIECE_ARBEITSNAME) + (B47D20, B48B20))"
Output:
(G011 + !(2VR_2_ACHS_LUFTFEDERUNG) + B47D20)
(G011 + !(2VS_MASTERPIECE_ARBEITSNAME) + B47D20)
(G011 + !(2VR_2_ACHS_LUFTFEDERUNG) + B48B20)
(G011 + !(2VS_MASTERPIECE_ARBEITSNAME) + B48B20)
Thanks in Advance
Reply
Answers (
1
)
0
Vulpes
0
96k
2.6m
Apr 29 2014 6:42 AM
Not an easy one but try this:
using System;
using System.Text.RegularExpressions;
class Test
{
static void Main()
{
string input = "(G011 + !(2VR_2_ACHS_LUFTFEDERUNG, 2VS_MASTERPIECE_ARBEITSNAME) + (B47D20, B48B20))";
string re = @"^(\(\w+\s*\+\s*)(!\()(.*?)(\)\s*\+\s*)\((.*?)\)(\))$";
Match m = Regex.Match(input, re);
string str1 = m.Groups[1].Value;
string str2 = m.Groups[2].Value;
string[] split1 = Regex.Split(m.Groups[3].Value, @",\s*");
string str4 = m.Groups[4].Value;
string[] split2 = Regex.Split(m.Groups[5].Value, @",\s*");
string str6 = m.Groups[6].Value;
Console.WriteLine(str6);
foreach(string s2 in split2)
{
foreach(string s1 in split1)
{
Console.WriteLine("{0}{1}{2}{3}{4}{5}", str1, str2, s1, str4, s2, str6);
}
}
Console.ReadKey();
}
}
Accepted Answer
Regular Expression of (B48B20 + G011 + !(ALLRAD))
sql 2000 with Having clause