Page 1 of 1

Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 5:56 am
by a.deivanai
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 ?

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 6:11 am
by prometheuzz
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 ?
Couple of questions:
- 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.

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 7:03 am
by a.deivanai
- 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.

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 7:22 am
by prometheuzz
a.deivanai wrote:...
* I need a regular expression which finds the position/index of the comma(,) which is not present in the brackets()
...
I see. This regex will match a comma which is not "inside" (balanced) parenthesis:

Code: Select all

,(?!([^()]*[()][^()]*[()])*[^()]*$)

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 8:12 am
by a.deivanai
Sorry,Your Regular Expression ,(?!([^()]*[()][^()]*[()])*[^()]*$)
dint work for my scenario.
Can you please check it once and let me know.

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 8:18 am
by prometheuzz
a.deivanai wrote:Sorry,Your Regular Expression ,(?!([^()]*[()][^()]*[()])*[^()]*$)
dint work for my scenario.
Can you please check it once and let me know.
Then you didn't implement it properly, or the tool/engine you're using doesn't support look-aheads.
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);
?>
And the output of the snippet above:

Code: Select all

abcd::("acd,gf(sdsd)")","desa::("asd,))
Array
(
    [0] => abcd::("acd,gf(sdsd)")"
    [1] => "desa::("asd,))
)

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 9:06 am
by a.deivanai
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")

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 9:29 am
by prometheuzz
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")
Well, I gave you more than enough to start with, surely you can (try to) adjust what I already showed you?
Good luck.

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 9:42 am
by a.deivanai
Yeah,Of course:)
I found the way to get the string which I really expect..
Thanks again.

Re: Seperate a string from combination of different strings with

Posted: Wed Mar 11, 2009 9:52 am
by prometheuzz
a.deivanai wrote:Yeah,Of course:)
I found the way to get the string which I really expect..
Thanks again.
Good to hear that, and you're welcome.