正则表达式问题:未正确提取字符串 [英] Problem with regex: a string is not extracted correctly

查看:175
本文介绍了正则表达式问题:未正确提取字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我有这段代码:

Hi everybody,

I have this code:

string Test = @"[Name]Hello";
Regex Finder = new Regex(@"^[\S]");
var Matches = Finder.Matches(Test);
string From = Matches[0].ToString();





我执行代码,但结果是一样的:只是'['从字符串中提取出来。我已经尝试过使用匹配[0] .value ,但没有任何问题...



有什么问题我的正则表达式?



提前致谢...



LG



PS:我实际上需要在方括号内找到任何字符,所以我也写了正则表达式 ^ [。*] ,但是如果字符串是 [Name姓氏]你好,不返回任何内容。



I execute the code, but the result is the same: just the '[' is extracted in the string from. I have tried even with Matches[0].value, but nothing chages...

What's wrong with my regex?

Thanks in advance...

LG

PS: I actually need to find any character inside the square brackets, so I have also written the regex ^[.*], but does not return anything if the string is [Name Surname]Hello.

推荐答案

我已经解决了我的问题:实际的正则表达式是 \ [[^ \]] * ] (昨天晚上我已经解决了,但我还有另外一个问题要解决,这就是这种类型的解决方案 [作者] [日期]评论,它提取 [作者] [日期]
I have solved my problem: the actual regex is \[[^\]]*] (I have solved it yesterday evening, but I had another little problem to solve, and this is the solution for a stirng of this type [author][date]Comment, it extracts [author] and [date].


仅回答从未答复的列表中删除:由OP解决。
Answered only to remove from the unanswered list: solved by OP.


这篇关于正则表达式问题:未正确提取字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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