【问题标题】:Regex For singlequote and doublequote正则表达式用于单引号和双引号
【发布时间】:2013-05-29 03:47:48
【问题描述】:

我只是想知道单引号和双引号的正则表达式是什么,特别是这样的 1:

openquote(startswith) + word + closequote(endswith)

(singlequote)word(/singlequote) sample-> 'asdasdasdass'

(doublequote)word(/doublequote) sample-> "asdasdasdass"

在 c#winforms 中/谢谢。

--- 更新:

在这一行中替换正则表达式:

string hoveredWord = r.GetFragment("[a-zA-Z]").Text;

谢谢!

【问题讨论】:

  • 这是我最喜欢的 .net 正则表达式游乐场之一derekslager.com/blog/posts/2007/09/…
  • @SabilValdano 我需要 c# 先生的正则表达式
  • @ps2goat 不错的工具,先生,但我不知道如何使用它。在“模式框”输出中输入的内容始终是数字列表,然后出现带有 @"" c# 的文本
  • 你应该阅读一下正则表达式模式,然后你可以自己制作或验证其他人给你的模式是否有效。 Source= 要在其中查找模式的字符串。 pattern = 普通正则表达式模式——不要将 @" 添加到开头或 " 在末尾添加,如结果列表中所示。结果列表显示了当前模式将根据您的源返回的所有匹配项。如果模式不是您所期望的,则匹配项可以为空。 @"" 文本是在 C# 中使用的模式——字符串前面的 @ 意味着您不必转义 C# 命令

标签: c# regex winforms


【解决方案1】:

以下 RegEx 用于 单引号 + 一些文本 + 单引号 ('asdasdasdass')

Regex regexString = new Regex(@"'[^']*'");

以下 RegEx 用于 双引号 + 一些文本 + 双引号 ("asdasdasdass")

Regex regexString = new Regex(@"""[^""]*""");

【讨论】:

    【解决方案2】:

    正则表达式模式:

    Former example : ^\'\w+\'
    Later example : ^\"\w+\"
    
    ^ : match the beginning of the string
    \' or \" : match the single quote or double quote
    \w+ : match the alpha-numeric characters and underscore
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-10-20
      • 1970-01-01
      • 1970-01-01
      • 2013-02-18
      相关资源
      最近更新 更多