Hi,
I have a String Like this
str = "450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
I want the Output like the below,
str1 = 450::Must be 9 numbers::("VILLEPA,16635")
str2 = 450::Must be 9 numbers::(""VILLEPARLE)
str3 = 276::Must not be blank::()
str4 = 450::Must be 9 numbers::(88,8::8,88,88)
str5 = 1187::Not found in eligibility table::(8888:::88,88"8")
I need a Regex for achiving the above output.
Basically I need a Regex which should seperate the string by using the comma(,) [which is not present inside the bracket() ] as delimeter.
Rule 1: There is no limitations for combinations of strings.In the above example i have combination of 5 strings.Sometimes it may contain only one string and sometimes it may have more than 10 strings.
Rule 2: Inside the bracket() ,it may have all kind of characters(alphanumeric and all the special chars)
(E.g) 1187::Not found in eligibility table::("" $ test %&^ @# '8888' ("testing")::('fact'):88,88"8")
Can anyone please help me on this Regex ?
Need a Regular Expression to Seperate a String
Moderator: General Moderators
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Need a Regular Expression to Seperate a String
Are you the same person as in this tread: viewtopic.php?f=38&t=96647?
If so, why did you create a new account?
Anyway, you can split on the the following substring:
(quote comma quote)
and you have your string as you wanted.
If so, why did you create a new account?
Anyway, you can split on the the following substring:
Code: Select all
","and you have your string as you wanted.
-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Need a Regular Expression to Seperate a String
Regex reg = ","(?!([^()]*[()][^()]*[()])*[^()]*$)
string str = "450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
reg.Split(str);
It is just displaying the input string as output.It is not splitting the strings.
"450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
string str = "450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
reg.Split(str);
It is just displaying the input string as output.It is not splitting the strings.
"450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Need a Regular Expression to Seperate a String
That's because you're not using it correctly.a.deivanai wrote:...
reg.Split(str);
It is just displaying the input string as output.It is not splitting the strings.
...
Have a look at the help pages for the split method:
http://www.php.net/preg_split
Edit: wait, it's you again...
In C#, you should do it like this:
Code: Select all
string[] substrings = Regex.Split(input, pattern);-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Need a Regular Expression to Seperate a String
Yeah,the syntax is Correct in C#.Net
The Regular Expression which you gave is just finding the comma(,) and splitting the strings
But I need a Regular Expression Which should find the comma(,) which is not present in the brackets() and then it should split the strings.
(E.g:1) abcd::("acd,gf(sdsd)")","desa::("asd,))
It is splitting correctly here as
abcd::("acd,gf(sdsd)")"
"desa::("asd,))
(E.g:2) "450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
Here it is not splitting the strings correctly.It is just giving the input string as output.
Can you just check this input string with the Regular Expression ","(?!([^()]*[()][^()]*[()])*[^()]*$) in PHP code and Please let me know.
The Regular Expression which you gave is just finding the comma(,) and splitting the strings
But I need a Regular Expression Which should find the comma(,) which is not present in the brackets() and then it should split the strings.
(E.g:1) abcd::("acd,gf(sdsd)")","desa::("asd,))
It is splitting correctly here as
abcd::("acd,gf(sdsd)")"
"desa::("asd,))
(E.g:2) "450::Must be 9 numbers::("VILLEPA,16635")","450::Must be 9 numbers::(""VILLEPARLE)","276::Must not be blank::()","450::Must be 9 numbers::(88,8::8,88,88)","1187::Not found in eligibility table::(8888:::88,88"8")"
Here it is not splitting the strings correctly.It is just giving the input string as output.
Can you just check this input string with the Regular Expression ","(?!([^()]*[()][^()]*[()])*[^()]*$) in PHP code and Please let me know.
-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Need a Regular Expression to Seperate a String
This Regular Expression is working fine for any combination of strings
","(?!([^()]*[()][^()]*[()])*$)
","(?!([^()]*[()][^()]*[()])*$)
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Need a Regular Expression to Seperate a String
I highly doubt that, but if you're content with it, you go ahead an use it!a.deivanai wrote:This Regular Expression is working fine for any combination of strings
","(?!([^()]*[()][^()]*[()])*$)
; )