Java Regex:提取版本号 [英] Java Regex: Extracting a Version Number

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

问题描述

我有一个程序,将版本号存储在文件系统上的文本文件中.我在java中导入了文件,并且想要提取版本号.我对正则表达式不太满意,因此希望有人能提供帮助.

I have a program that stores the version number in a text file on the file system. I import the file within java and I am wanting to extract the version number. I'm not very good with regex so I am hoping someone can help.

文本文件如下所示:

0=2.2.5 BUILD (tons of other junk here)

我想提取2.2.5.没有其他的.有人可以帮我做正则表达式吗?

I am wanting to extract 2.2.5. Nothing else. Can someone help me with the regex for this?

推荐答案

如果您知道结构,则不需要正则表达式:

If you know the structure, you don't need a regex:

    String line = "0=2.2.5 BUILD (tons of other junk here)";
    String versionNumber = line.split(" ", 2)[0].substring(2);

这篇关于Java Regex:提取版本号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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