Click here to Skip to main content
15,893,190 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
Hi experts,
C#
string Input = "@a = '1', @b = 'hello@123.com,hi@123.com'"

I want to split Input string and want output as below using regex
C#
ary[0] = a = '1'
ary[1] = b = 'hello@123.com'


I want to split by @ and it should not be in single quotes
thanks in adv.
Posted
Updated 20-Aug-13 23:26pm
v2

Don't use a regex, just use string.Split:
C#
string Input = "@a = '1', @b = 'hello@123.com,hi@123.com'"
string[] ary = Input.Split(',');
 
Share this answer
 
Comments
Aarti Meswania 21-Aug-13 5:10am    
Thanks for reply :)
if I split string by comma then it will result
@a = '1'
@b = 'hello@123.com
hi@123.com'

I don't want to split 'hello@123.com,hi@123.com'
I got solution after some trial & error,
Hope it will useful for people have same requirement
C#
string Input = "@a = '1', @b = 'hello@123.com,hi@123.com'"
string Output = Regex.Split(Input, @"(?=@\w+[ =|=])@")

(condition)true|false
(?=@\w+[ =|=]) condition 
@              if true then split by @


--condition work as below

?         In supplied input What
=         is equal to   
@\w+      a(single) word that start with @
[ =|=]    and after the word end it contain space+= or =

Happy Coding!
:)
 
Share this answer
 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900