Seperate a string from combination of different strings with
Moderator: General Moderators
-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Seperate a string from combination of different strings with
Hi,
I have string like this in C#.NET
string s="{"abcd::("11,23",)(@$",")","efgh::("adas",::")"}"
it is a combination of 2 strings,
string1 = "abcd::("11,23",)(@$",")"
string2 = "efgh::("adas",::")"
The default format of the string is { "some string::()","some string::()","some string::()" }
inside the bracket ( ) it may have any characters.. (comma,",:,',(,),{,} ,etc.,)
i want to seperate the strings.I dont know how to fix this issue.
Can anyone help me to split the strings ?
I have string like this in C#.NET
string s="{"abcd::("11,23",)(@$",")","efgh::("adas",::")"}"
it is a combination of 2 strings,
string1 = "abcd::("11,23",)(@$",")"
string2 = "efgh::("adas",::")"
The default format of the string is { "some string::()","some string::()","some string::()" }
inside the bracket ( ) it may have any characters.. (comma,",:,',(,),{,} ,etc.,)
i want to seperate the strings.I dont know how to fix this issue.
Can anyone help me to split the strings ?
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Seperate a string from combination of different strings with
Couple of questions:a.deivanai wrote:Hi,
I have string like this in C#.NET
string s="{"abcd::("11,23",)(@$",")","efgh::("adas",::")"}"
it is a combination of 2 strings,
string1 = "abcd::("11,23",)(@$",")"
string2 = "efgh::("adas",::")"
The default format of the string is { "some string::()","some string::()","some string::()" }
inside the bracket ( ) it may have any characters.. (comma,",:,',(,),{,} ,etc.,)
i want to seperate the strings.I dont know how to fix this issue.
Can anyone help me to split the strings ?
- if there can be parenthesis inside the parenthesis, how do you know which is the closing, or opening parenthesis? Are the parenthesis inside escaped or something?
- can you give a couple of example strings and their corresponding values you wish to extract?
- can you post what you have tried yourself to solve this?
- you know this is a regex/PHP forum, right?
So, if you're looking for a C# solution, you should post in a C# forum. Of course, if you're not looking for C# code but only a PCRE regex, you' mind as well stick around.
-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Seperate a string from combination of different strings with
- if there can be parenthesis inside the parenthesis, how do you know which is the closing, or opening parenthesis? Are the parenthesis inside escaped or something?
* No the paranthesis are not escaped.
- couple of example strings and their corresponding values I wish to extract
* This is the combination of 2 strings
"abcd::("acd,gf(sdsd)")","desa::("asd,))"
* I want the result string should be a seperation of 2 individual strings
"abcd::("acd,gf(sdsd)")"
"desa::("asd,))"
- yeah,I know this is a regex forum.
* I need a regular expression which finds the position/index of the comma(,) which is not present in the brackets()
* I hope this will give the solution for this issue.
* By finding the index of the comma ,I can seperate the strings by using comma as delimeter.
* No the paranthesis are not escaped.
- couple of example strings and their corresponding values I wish to extract
* This is the combination of 2 strings
"abcd::("acd,gf(sdsd)")","desa::("asd,))"
* I want the result string should be a seperation of 2 individual strings
"abcd::("acd,gf(sdsd)")"
"desa::("asd,))"
- yeah,I know this is a regex forum.
* I need a regular expression which finds the position/index of the comma(,) which is not present in the brackets()
* I hope this will give the solution for this issue.
* By finding the index of the comma ,I can seperate the strings by using comma as delimeter.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Seperate a string from combination of different strings with
I see. This regex will match a comma which is not "inside" (balanced) parenthesis:a.deivanai wrote:...
* I need a regular expression which finds the position/index of the comma(,) which is not present in the brackets()
...
Code: Select all
,(?!([^()]*[()][^()]*[()])*[^()]*$)-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Seperate a string from combination of different strings with
Sorry,Your Regular Expression ,(?!([^()]*[()][^()]*[()])*[^()]*$)
dint work for my scenario.
Can you please check it once and let me know.
dint work for my scenario.
Can you please check it once and let me know.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Seperate a string from combination of different strings with
Then you didn't implement it properly, or the tool/engine you're using doesn't support look-aheads.a.deivanai wrote:Sorry,Your Regular Expression ,(?!([^()]*[()][^()]*[()])*[^()]*$)
dint work for my scenario.
Can you please check it once and let me know.
This being a PHP forum, here's my PHP test that proves all goes well:
Code: Select all
<?php
$test = 'abcd::("acd,gf(sdsd)")","desa::("asd,))';
echo $test . "\n";
$tokens = preg_split('/,(?!([^()]*[()][^()]*[()])*[^()]*$)/', $test);
print_r($tokens);
?>Code: Select all
abcd::("acd,gf(sdsd)")","desa::("asd,))
Array
(
[0] => abcd::("acd,gf(sdsd)")"
[1] => "desa::("asd,))
)-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Seperate a string from combination of different strings with
Thanks a lot..
The input string : {"1259::Procedure not found in table::(E**5254)","276::Must not be blank::("test data","deivanai")"}
Always the input string will have open brace({) and closed brace(}) and every string will be enclosed by open quotes(") and closing quotes(").I want to remove those open and closed braces and also the open and closed quotes from the string.
I want the output as, (it shoudnt have any enclosed quotes)
string 1 : 1259::Procedure not found in table::(E**5254)
string 2 : 276::Must not be blank::("test data","deivanai")
The input string : {"1259::Procedure not found in table::(E**5254)","276::Must not be blank::("test data","deivanai")"}
Always the input string will have open brace({) and closed brace(}) and every string will be enclosed by open quotes(") and closing quotes(").I want to remove those open and closed braces and also the open and closed quotes from the string.
I want the output as, (it shoudnt have any enclosed quotes)
string 1 : 1259::Procedure not found in table::(E**5254)
string 2 : 276::Must not be blank::("test data","deivanai")
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Seperate a string from combination of different strings with
Well, I gave you more than enough to start with, surely you can (try to) adjust what I already showed you?a.deivanai wrote:Thanks a lot..
The input string : {"1259::Procedure not found in table::(E**5254)","276::Must not be blank::("test data","deivanai")"}
Always the input string will have open brace({) and closed brace(}) and every string will be enclosed by open quotes(") and closing quotes(").I want to remove those open and closed braces and also the open and closed quotes from the string.
I want the output as, (it shoudnt have any enclosed quotes)
string 1 : 1259::Procedure not found in table::(E**5254)
string 2 : 276::Must not be blank::("test data","deivanai")
Good luck.
-
a.deivanai
- Forum Newbie
- Posts: 8
- Joined: Wed Mar 11, 2009 5:46 am
Re: Seperate a string from combination of different strings with
Yeah,Of course:)
I found the way to get the string which I really expect..
Thanks again.
I found the way to get the string which I really expect..
Thanks again.
- prometheuzz
- Forum Regular
- Posts: 779
- Joined: Fri Apr 04, 2008 5:51 am
Re: Seperate a string from combination of different strings with
Good to hear that, and you're welcome.a.deivanai wrote:Yeah,Of course:)
I found the way to get the string which I really expect..
Thanks again.