在.NET中使用Regex查找版本号 [英] Find version number with Regex in .NET

查看:123
本文介绍了在.NET中使用Regex查找版本号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的英语有点粗糙,所以请耐心等待我的语法。



我有以下正则表达式来查找字符串中的版本号,示例此用户代理:Opera / 9.80(Windows NT 6.0)Presto / 2.12.388版本/ 12.14,



1.(\d + \。) ?(\d + \。)?(\d + \。)?(\ * | \d +)

2.(\ * |(\d +(\ 。(\d +(\。(\ d + | \ *))?| \ *))?))



我相信这意味着(并纠正我在哪里错了):

1:前三组意味着最多3位数字,但在第四组中,\ *是什么吗?

2:再次,\ *是做什么的?

My english is a little bit unpolished, so please be patient with my grammatics.

I have the following regex's to find a version number in a string, for example this user agent: "Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14",

1. (\d+\.)?(\d+\.)?(\d+\.)?(\*|\d+)
2. (\*|(\d+(\.(\d+(\.(\d+|\*))?|\*))?))

which I believe means (and correct me where I'm wrong):
1: the first 3 groups means "up to 3 digit(s)-dot", but in the fourth, what does the "\*" do?
2: again, what does the "\*" do?

推荐答案

如果您不确定,那么最好的办法是获取Expresso的副本: http://www.ultrapico.com/expresso.htm [ ^ ]

它是免费的,它解释说,可以帮助你创建和测试正则表达式 - 我一直使用它,真的希望我写它。 (我希望它也有一个Android版本。)



正则表达式中的\ *是文字* - 所以

If you aren't sure, then the best thing to do is to get a copy of Expresso: http://www.ultrapico.com/expresso.htm[^]
It's free, and it explains, helps you create and tests Regexes - I use it all the time and really wish I'd written it. (And I wish it came in an Android version, too).

"\*"in a Regex is a literal "*" - so
(\*|\d+)

匹配单个星号或一个或多个数字。

matches a single star or one-or-more digits.


这篇关于在.NET中使用Regex查找版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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