如何使用正则表达式删除括号文本 [英] How to remove text in brackets using a regular expression

查看:125
本文介绍了如何使用正则表达式删除括号文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在寻找一个正则表达式,将执行以下操作:

I'm looking for a regular expression which will perform the following:

INPUT: User Name (email@address.com)
OUTPUT: User Name

什么是实现这一目标的最佳途径?使用正则表达式来提取括号内的文字和替换这一点,任何)(字符?

What would be the best way to achieve this? Using regular expression to extract the text within the brackets and replacing this and any )( characters?

任何帮助,将不胜感激,

Any help would be appreciated,

感谢

推荐答案

这应该做的工作:

var input = "User Name (email@address.com)";
var output = Regex.Replace(input, @" ?\(.*?\)", string.Empty);

请注意的转义的字符,使他们不被视为组标记。

Note the escaping of the ( and ) chars so that they aren't recognised as group markers.

这篇关于如何使用正则表达式删除括号文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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