4

I'm attempting to find a regular expression that will match the following strings:

##Content##
##AnotherArea##

So far I've tried

@"\\#\\#(.*?)\\#\\#"
@"\\#\\#(*?)\\#\\#"

But neither seem to find anything when running:

foreach (var match in Regex.Matches(txtPageContent.Text, expressionMatch))

Where expression match is a string containing the expressions.

Can anyone help me out on this?

2
  • 1
    There's no need to escape # Commented Oct 11, 2012 at 6:05
  • This SO Answer helps you to solve your issue. Please see to this. stackoverflow.com/questions/4884915/… Commented Oct 11, 2012 at 6:09

1 Answer 1

5

no need to escape #.

##.*?##

simple explanation

Options: ^ and $ match at line breaks

Match the characters “##” literally «##»
Match any single character that is not a line break character «.*?»
   Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the characters “##” literally «##»
Sign up to request clarification or add additional context in comments.

3 Comments

But I think he wants the sub-group match (or whatever that's called).
its still OK to escape it unless he uses verbatim string
Awesome, thanks a lot for the explanation as well. I know nothing about regex.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.