Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 删除正则表达式中的空白_C#_Regex - Fatal编程技术网

C# 删除正则表达式中的空白

C# 删除正则表达式中的空白,c#,regex,C#,Regex,我正在尝试编写一个正则表达式代码来删除空格、第一个单词、括号和所有数字 我有以下案文: {a, 1, b, 4, c, 6, d, 8} 我对b、c和d感兴趣,但不包括a 这个正则表达式:“\,([^{^,+^\d-}]*)”给了我b、c和d,但带有空格 我试过:“\,([^{^,+^\d-^\s+}]*)”,但运气不好 有什么建议吗?在您的情况下,最简单的解决方案是提取所有字母并忽略第一个匹配: var matches = Regex.Matches(inputText, @"\p{L}+"

我正在尝试编写一个正则表达式代码来删除空格、第一个单词、括号和所有数字

我有以下案文:

{a, 1, b, 4, c, 6, d, 8}
我对b、c和d感兴趣,但不包括a

这个正则表达式:
“\,([^{^,+^\d-}]*)”
给了我b、c和d,但带有空格

我试过:
“\,([^{^,+^\d-^\s+}]*)”
,但运气不好


有什么建议吗?

在您的情况下,最简单的解决方案是提取所有字母并忽略第一个匹配:

var matches = Regex.Matches(inputText, @"\p{L}+")
                   .Cast<Match>()
                   .Skip(1)
                   .Select(match => match.Value)
                   .ToList();
这意味着:

^\{                     # Opening brace
  (?:                   # Optionally:
    (?:\s*\w+\s*,\s)*   #   Words followed by commas 0 to n times
    \s*\w+              #   Followed by a word
  )?                    
\s*                     # Optional whitespace
\}$                     # Closing brace

您使用的是什么语言/工具?您想用什么语言来实现这一点?因为修剪
{}
并在
处拆分,
会容易得多。语言工具是C#它绝对必须是正则表达式吗?我可以想出其他方法来做到这一点,可能同样快速,性能明智。
^\{                     # Opening brace
  (?:                   # Optionally:
    (?:\s*\w+\s*,\s)*   #   Words followed by commas 0 to n times
    \s*\w+              #   Followed by a word
  )?                    
\s*                     # Optional whitespace
\}$                     # Closing brace