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

x

regex expression c#

Medium Priority
468 Views
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:

  <h1>$/information_page/paragraphtitle$</h1>
            <div class="maintext">
                 $/information_page/paragraphmaintext$
            </div>

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)

Thanks
Comment
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

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

Commented:
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.

OR

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.