我怎样才能匹配所有字符?

发布于 2024-10-12 12:59:07 字数 636 浏览 5 评论 0原文

例如,我如何匹配 regex.match 中的每个可能的字符。

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

匹配

,"message":"all characters here",

与我尝试过的

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

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

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

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

,但没有一个起作用。

编辑:

我与 ,"message":"allcharactershere", 匹配的值可以在“allcharactershere”部分中包含任何字符,我想匹配 < 的所有实例code>,"message":"这里的所有字符", 忽略第二组引号之间的内容

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

刘备忘录 2024-10-19 12:59:07

如果您不希望值中出现任何引号,则可以使用:

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

写为

  • "\"message\":\"([^\"]*)\"" - 作为常规字符串文字
  • @"""message"":""([^""]*)""" 作为 逐字字符串)

如果您已转义引号,则一个选项是这样,它也允许所有转义字符:

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

写为:

  • "\"message\":\"(([^\"\\\\]|\\ \\.)*)\""
  • @"""消息"":""(([^""\\]|\\.)*)"""

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"":""(([^""\\]|\\.)*)"""
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文