VB.Net 正则表达式...提取值 [英] VB.Net Regex...extracting a value

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

问题描述

如何在 VB.Net 中使用 RegularExpressions 类从字符串中提取值?例如,假设我有字符串:

How in VB.Net can I extract the value from a string using the RegularExpressions class? For example, say I have the string:

[Mon Jan 4 2011] Blah Blah2 Other text

并且我想将Mon Jan 4 2011"部分返回到一个变量中.我以为你会使用Regex.Replace"方法,但我似乎无法弄清楚如何提取我想要的字符串部分.

and I want to return the "Mon Jan 4 2011" portion in to a variable. I thought you would use the "Regex.Replace" method but I can't seem to figure out how to extract the portion of the string I want.

推荐答案

这种情况下,我认为你不需要替换文本,你需要匹配文本.

In this case, I don't think you need to replace the text, you need to match the text instead.

Regex.Match(input, "(?<=\[)[^\]]+").Value

这将获取从第一个 [ 之后到下一个 ] 的所有文本.错过了一个方括号.

This takes all the text from right after the first [ up until the next ]. missed a square bracket.

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

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