We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now


regex expression c#

Medium Priority
Last Modified: 2012-05-11
I have a string in c# and i need a regex solution to get all matches.
An example string is:

            <div class="maintext">

I need to have all the items which start with "$/" and end with "$" so in this example "/information_page/paragraphtitle" and "/information_page/paragraphmaintext".

The items can be inside a text (not separated by spaces) and all kind of characters (a-z,0-9,/ and _) can be inside. In between the two delimeters are no spaces allowed (not necessary in regex)

Watch Question

The pattern to match the strings as requested is:  

Open in new window

The code to iterate the matches would be:

using System.Text.RegularExpressions;


foreach (Match match in Regex.Matches(yourHtmlString, @"\$/.*\$", RegexOptions.IgnoreCase))
  string val = match.Value;
  // Do something with you matched strings.


Open in new window

Most Valuable Expert 2011
Top Expert 2015
Unlock this solution with a free trial preview.
(No credit card required)
Get Preview
Most Valuable Expert 2011
Top Expert 2015

My "output" from the "bad" regex should have included a trailing "$". Copy/paste didn't show me any love on that one  : )
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a free trial preview!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.