Click here to Skip to main content
15,890,845 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want a regular expression which will find a string which is enclosed in double quotes and starts with $.

Example:

input : "$abcd" ("abcd" can any string)
output : abcd

input can be array of string or a string which contains multiple combination of input ("$abcd").

After getting output i want to replace that string with other word.

Please help me on this.

Thank you.
Posted
Comments
Manfred Rudolf Bihy 8-Aug-13 14:27pm    
So what have you tried and where exactly are you stuck?

Cheers!
Member 10193563 8-Aug-13 15:01pm    
I have tried it by find it by using the
int start = indexOf('$')
int end = indexOf('"')
string str = substring(start+1,end-1,(end-start))

but i am not getting expected result.
Actually i am reading xml file into string array by using File.ReadAllLines() method. And i want find all strings which starts with $ enclosed in double quotes. After that i want to reaplce that word with other string.

1 solution

You havent defined your search very good, so the regex could be defined as this:
C#
string MatchString = "["][$](?<Name>[A-Za-z]+)["]";

You can test out expressions with this tool:
http://www.ultrapico.com/expresso.htm[^]
 
Share this answer
 
v2
Comments
Member 10193563 8-Aug-13 15:04pm    
Actually my question is how to get string a which starts with $ and enclosed in double quotes.
example:
input : "$abcd"
output: abcd
Kenneth Haugland 8-Aug-13 15:05pm    
THe capturegroup Name gives the string.
Member 10193563 8-Aug-13 15:18pm    
There is some error in regular expression. There is issue of double quotes.
Kenneth Haugland 8-Aug-13 15:33pm    
Did you use the capturegroupe as a result? Cos I couldnt find a proble, vould you give an example?
Member 10193563 8-Aug-13 15:44pm    
Hey thanks a lot.... I got the solution.... It really helped me...Thank you very much.

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