正则表达式是什么? [英] What is the RegEx for this?

查看:109
本文介绍了正则表达式是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有各种各样的字符串,它们可能包含也可能不包含(_#)",其中#"是一个数字(也可以是多个数字.

请注意,有时它不存在(整个序列),但如果存在,则总是在开头.我想删除它以用于显示目的(如果存在),因此我认为RegEx可以轻松做到这一点(我知道它确实可以),但是我很生锈.

这是一些字符串示例

I have various strings that may or may not contain ''(_#)'' where ''#'' is a number (can be multiple digits also.

Note sometimes it does not exist (the whole sequence), but if it does it is always at the beginning. I want to remove it for display purposes if it exists, so I thought RegEx would do this easily (well I know it does), but I am quite rusty.

Here are some string examples

(_0) Welcome
(_1) Information
(_2) Products
(_3) Help
Contact Info
Maps
Celery
Wild Wings
Deep Fried Pickles
(_4) Your thinking about BWW now



因此所有这些字符串都以某个变量s结尾,我想删除(_#)"(如果存在)并将该字符串存储在display中.

预先谢谢您.



So all of these strings end up in some variable s and I want to rip out the ''(_#)'' if it exists and store the string in display.

Thank you in advance.

推荐答案

尝试:
public static Regex regex = new Regex(
      @"^\(_\d*\)\s*",
    RegexOptions.IgnoreCase
    | RegexOptions.Multiline
    | RegexOptions.CultureInvariant
    | RegexOptions.IgnorePatternWhitespace
    | RegexOptions.Compiled
    );

string result = regex.Replace(InputText,"");



获取 Expresso [ ^ ]-它是免费的,它检查并生成正则表达式.一旦我测试了正则表达式,它就会生成代码!



Get a copy of Expresso [^] - it''s free, and it examines and generates Regular expressions. It generated the code once I had tested the regex!


这篇关于正则表达式是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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