Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/290.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/18.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,我在一个字符串上使用了一个正则表达式,我有一个问题,就是字符串左边没有任何东西在字符串中多次出现 ">something">tofind</a> 左边的部分不是 如何使表达式取(待匹配)值左侧的第一个“>而不是字符串开头的第一个“ \">(.*)</a> var regex = new Regex(regexstring); var matches = regex.Ma

我在一个字符串上使用了一个正则表达式,我有一个问题,就是字符串左边没有任何东西在字符串中多次出现

">something">tofind</a>
左边的部分不是

如何使表达式取(待匹配)值左侧的第一个“>而不是字符串开头的第一个“

\">(.*)</a>
                    var regex = new Regex(regexstring);

                    var matches = regex.Matches(line);

                    foreach (var singleuser in matches.Cast<Match>().ToList())
                    {
                        allusernames.Add(singleuser.Groups[1].Value);
                    }
\”>(.*
因此无法正常工作,并给我“>找到正确答案

有解决方案吗?我希望我的问题的解决方案在表达式中,而不是附加代码。由于我不太愿意硬编码,所以我可能会对字符串中的每个特殊问题进行修复

非常感谢

处理字符串的代码

\">(.*)</a>
                    var regex = new Regex(regexstring);

                    var matches = regex.Matches(line);

                    foreach (var singleuser in matches.Cast<Match>().ToList())
                    {
                        allusernames.Add(singleuser.Groups[1].Value);
                    }
var regex=newregex(regexstring);
var matches=regex.matches(行);
foreach(matches.Cast().ToList()中的var singleuser)
{
添加(singleuser.Groups[1].Value);
}

您可以使用以下功能

\">([^>]*)</a>
\”>([^>]*)
说明:

  • \“>
    匹配文字
    \“>
  • ([^>]*)
    匹配除
    之外的所有字符(
    [^>]
    设置为否定)
  • 匹配文字

请参见

作为旁注,这是一种在C#中处理HTML的极好方法!可能是重复的东西“>找到了要处理的文字,你在里面寻找的是什么东西?我的英雄!你能简单地解释一下你做了什么吗?很好的解释,这是用户需要的。