如何在C#中使用正则表达式获取字符串outside() [英] How to get string outside () using regex in C#

查看:60
本文介绍了如何在C#中使用正则表达式获取字符串outside()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的,我想从下一个(荷兰)KPN获得KPN字符串

使用C#和正则表达式和特殊使用

Dears, i want to get KPN string from the following one (NETHERLANDS)KPN
using C# and regex and special using

Regex.Matches





换句话说我想终止它之间的()和th值以保持在这种情况下的值外终止(NETHERLANDS)并保持KPN



谢谢



我的尝试:



i尝试了这个,但它正在做相反的事情:



in other word i want to terminate the () and th value between it to keep the value outside in this case terminate (NETHERLANDS) and keep KPN

Thanks

What I have tried:

i tried this but it is doing the opposite things:

string input = "(Vaue 1) test + test(Vaue 2)bbb * aaa(Vaue 3)";
var matches = Regex.Matches(input, @"(?<=\().+?(?=\))")
                    .Cast<match>()
                    .Select(m => m.Value)
                    .ToList();

foreach (var item in matches)
{
    Console.WriteLine(item);
}

Console.Read();</match>

推荐答案

您是否尝试过使用 Regex.replace 而不是 Regex.matches



希望此链接有用

Debuggex:在线可视正则表达式测试器。 JavaScript,Python和PCRE。 [ ^ ]
Did you try to use Regex.replace instead of Regex.matches ?

Hope this link will help
Debuggex: Online visual regex tester. JavaScript, Python, and PCRE.[^]


您好,只需尝试以下功能,

Hi, just try the following function,
private string FindMatch()
{
    string input = textBox1.Text.Trim();
    MatchCollection Matches = Regex.Matches(input, @"(\(.+?\))");

    foreach (Match match in Matches)
    {
        input = input.Replace(match.Value, "");
    }

    return input;
}


这篇关于如何在C#中使用正则表达式获取字符串outside()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆