1

How can i match every possible character in regex.match for example.

string value4 = (",\"message\":\"all characters\",");
Match[] message = Regex.Matches(docText, @value4)

matched against

,"message":"all characters here",

I have tried

string value4 = (",\"message\":\".\","); 

string value4 = (",\"message\":\"[.]\","); 

string value4 = (",\"message\":\"[.*]\",");

string value4 = (",\"message\":\".*\",");

and none of them worked.

Edit:

the value that i'm matching against ,"message":"all characters here", can have any characters in the "all characters here" section, I would like to match all instances of ,"message":"all characters here", ignoring what is in between the second set of quotes

user556396
  • 597
  • 3
  • 12
  • 26
  • 1
    What are you trying to do? By the way, In C#, `@value4` is the same as `value4`: http://stackoverflow.com/questions/254669/what-does-placing-a-in-front-of-a-c-variable-name-do – Kobi Jan 16 '11 at 05:50

1 Answers1

1

If you don't expect any quotes in your value, you can use:

"message":"([^"]*)"

Which is written as

  • "\"message\":\"([^\"]*)\"" - as a regular string literal
  • @"""message"":""([^""]*)""" as a Verbatim String)

If you have escaped quotes, one option is this, which also allows all escaped characters:

"message":"(([^"\\]|\\.)*)"

Written as:

  • "\"message\":\"(([^\"\\\\]|\\\\.)*)\""
  • @"""message"":""(([^""\\]|\\.)*)"""
Kobi
  • 135,331
  • 41
  • 252
  • 292
  • @user556396 - please edit that into the question, and explain what you're trying to do. I obviously misunderstood `:P` – Kobi Jan 16 '11 at 05:53
  • Edited, hope that makes more sense – user556396 Jan 16 '11 at 05:57
  • Ahh yes thank you for helping me out with that, the escape characters were preventing the match. Thanks. – user556396 Jan 16 '11 at 06:04
  • @user556396 - No problem, happy to help. I was writing a short code example, but I guess you don't need it. There are oddities in the code - for example, `Regex.Matches` does not return an array, but a `MatchCollection` (though I assume that's just sample code). Anyway, good luck! – Kobi Jan 16 '11 at 06:08