In C#, how do I find all the words starting with ‘$’ sign and ending with space, in a long string, using regular expressions?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Try:
In the above,
\\wmatches word characters. These are A-Z, a-z, – and _ if I’m correct. If you want to match everything that’s not a space, you can use\\S. If you want a specific set, specify this through e.g.[a-zA-Z0-9].The brackets around the
(\\$\\w+)ensures that of a specific match,matches[0].Groups[1].Value;gives the value inside the backets (so, excluding the trailing space).As a complete example:
This produces the following output:
The $b2 is of course omitted because it does not have a trailing space.