我缺乏使用正则表达式的经验,需要一些帮助。 我需要提取一个 git 标签。输入的字符串是这样的:
6dde3d91f23bff5ab81e91838f19f306b33fe7a8refs/tags/3.4.2
// there is a new line at the end of the string
我需要的字符串部分是3.4.2
。这是我的代码:
var pattern = /.*([0-9]{1}\.{1}[0-9]{1}\.{1}[0-9]{1}).*/ig;
var match = pattern.exec(string);
// match[1] gets what I need
它有效,但是这个正则表达式长得离谱,必须有办法让它更短。有人可以帮助我吗?
谢谢
最佳答案
关于javascript - 需要一些帮助来改进正则表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12923652/