regex - sed 从字符串中提取版本号(只有版本,没有其他数字)

标签 regex bash shell sed

我想实现与 sed: Extract version number from string 中解释的相同的效果, 但只考虑第一个数字序列或更安全,告诉 sed 只保留命令名称后面的数字序列,而忽略其余部分。

我有: Chromium 12.0.742.112 Ubuntu 11.04

我要: 12.0.742.112

代替: 12.0.742.11211.04

我现在知道使用 head 或 tail 和 sort 可以显示最大/最小数字,但我如何告诉 sed 只考虑第一个序列?

编辑:我忘了说我正在使用 bash。

最佳答案

第一个数字?怎么样:

sed 's/[^0-9.]*\([0-9.]*\).*/\1/'

关于regex - sed 从字符串中提取版本号(只有版本,没有其他数字),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7516455/

相关文章:

regex - (ReasonML) 正则表达式\b 不匹配

正则表达式以任意顺序匹配 0 个或多个关键字实例

javascript - 名字和姓氏正则表达式

linux - Linux 中的模糊重定向

java - 如何杀死在服务器上运行的进程

javascript - 将目标 ="_blank"添加到某些尚未指定目标的链接

bash - bash 中的命令行参数到 Rscript

linux - linux shell脚本中for循环的语法

linux - BASH 脚本 : take a filename (with spaces) as argument and use name (no ext) and also full filename as args for scripted command

Python:并行执行cat子进程