Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.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# RegEx获取双引号之间的文本格式字符串,其中至少包含一个类似<<;=>>;=<>;,_C#_Regex_C# 4.0 - Fatal编程技术网

C# RegEx获取双引号之间的文本格式字符串,其中至少包含一个类似<<;=>>;=<>;,

C# RegEx获取双引号之间的文本格式字符串,其中至少包含一个类似<<;=>>;=<>;,,c#,regex,c#-4.0,C#,Regex,C# 4.0,正则表达式以获取双引号之间的文本格式字符串,其中至少包含一个 :=、&&、| |、=、=、、&、+、-、*、/、 代码: script=“如果(a事实上看起来并不是那么简单 我建议首先查找双引号之间的所有字符串,“…”,然后检查每个字符串是否包含您提供的特殊字符。因此如下所示: 正则表达式: (?您可以发布您尝试过的内容吗?另外,最好包括示例(示例输入/预期输出)或清楚地解释您想要的内容(例如,您是否希望字符串包含双引号之间的一位或多个位)。此外,您是否只对正则表达式解决方案感兴趣?我尝试过,但

正则表达式以获取双引号之间的文本格式字符串,其中至少包含一个

:=、&&、| |、=、=、、&、+、-、*、/、

代码:


script=“如果(a事实上看起来并不是那么简单

我建议首先查找双引号之间的所有字符串,“…”,然后检查每个字符串是否包含您提供的特殊字符。因此如下所示:

正则表达式
  • (?您可以发布您尝试过的内容吗?另外,最好包括示例(示例输入/预期输出)或清楚地解释您想要的内容(例如,您是否希望字符串包含双引号之间的一位或多个位)。此外,您是否只对正则表达式解决方案感兴趣?我尝试过,但我没有得到正则表达式来获得双引号字符串,它包含任何字符串,如=…我需要正则表达式。正如所说,正则表达式不是字符串管理的alpha和omega,您可以尝试不同的方法。您应该展示您尝试过的任何方法;记住它是如何工作的:您有向我们展示您自己做了一些努力。很明显,您发布的代码没有说明任何内容。而且您还没有定义问题属性。@ThulasiRam我认为您在问题描述中遗漏了“=”字符。您还可以添加一些清晰的示例,或者至少添加一个示例来说明您想要实现的目标。@Tafari:我需要在双引号之间获取文本,它包含任何字符串,比如=…@ThulasiRam,这是真的,但是当它们是seprate时更容易理解。但是我还提供了一个regex,它也可以完成这项工作:)干杯,很高兴我能帮上忙。
    
     script = "if(a<=b, strcat(\" userid <= 'tom' \",\" and test = 1\", \" and test >= 10 \"), nop());";
    string tempScript = (script ?? "").Trim();
    
    var functionMatches = Regex.Matches(tempScript, @"Some RegEx");
    if (functionMatches != null && functionMatches.Count > 0)
    {
        foreach (Match fm in functionMatches)
        {
            Console.WriteLine(fm.Value);
        }
    }
    
    Console.ReadLine();
    
    Input :- 
        "if(a<=b, strcat(" userid <= 'tom' "," and test = 1", " and test >= 10 "), nop());"
    
    Output :-
    
        1) " userid <= 'tom' "
    
        2) " and test >= 10 "
    
    string pattern = "(?<=\")[^,]+?(?=\")";
    string patternSpecial = @"^.+?(<=|>=|<>|\|\||:=|&&|==|<|>|&|\+|-|\*|/|\?).+?$";
    string input = "if(a<=b, strcat(\" userid <= 'tom' \",\" and test = 1\", \" and test >= 10 \"), nop());";  
    
    foreach (Match m in Regex.Matches(input, pattern))
    {
        if (Regex.IsMatch(m.Value, patternSpecial))
        {
            Console.WriteLine(Regex.Match(m.Value, patternSpecial).Value);
        }
    }
    
    Console.ReadLine();
    
    \"([^"]+?(<=|>=|<>|\|\||:=|&&|==|<|>|&|\+|-|\*|/|\?).+?)\"
    
    string pattern = "\"([^\"]"+@"+?(<=|>=|<>|\|\||:=|&&|==|<|>|&|\+|-|\*|/|\?).+?)"+"\"";
    string input = "if(a<=b, strcat(\" userid <= 'tom' \",\" and test = 1\", \" and test >= 10 \"), nop());";  
    
    foreach (Match m in Regex.Matches(input, pattern))
    {
        Console.WriteLine(m.Groups[1]);
    }
    
    Console.ReadLine();