regex - 使用正则表达式解析 bash 中的分隔数组

标签 regex bash svg grep pcre

我有一个包含以下行的文件:

<polyline id="graph" points="0,287 100,470 200,509 300,459 400,471"/>

我需要提取以下值:

287 470 509 459 471

我目前正在使用此代码:

grep -oP '(?<=points=").*(?="/>)' "file.svg" | grep -oP '(?<=,)[[:digit:]]*'

我想用一个grep来做到这一点,我尝试使用 (?:) ,没有成功。有什么建议吗?

最佳答案

sed 解决方案可以是这样的

$ sed -r '/points=/ s/[^,]+,?([0-9]*)/\1 /g' input
287 470 509 459 471 

或者

更好的处理

$ sed -r '/points=/ s/.*points=("[^"]+").*/\1/g; s/[^,]+,?([0-9]*)/\1 /g' input
287 470 509 459 471 

关于regex - 使用正则表达式解析 bash 中的分隔数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27078281/

相关文章:

c# - C# 中的正则表达式 - 如何仅替换 Match 中的一个特定组?

Bash 4.3.33 中的字符串替换(小写)- 错误替换错误

javascript - 使用 https 命名空间时 createElementNS 无法正常工作

javascript - 在 SVG 路径上实现 Div 对象

javascript - 使用正则表达式前瞻匹配特殊字符

c# - 使用 .NET Regex 进行泰米尔语全词搜索

bash - 如何在 bash "for loop"中使用 ffmpeg 流复制?

linux - bash 管道处理

javascript - 如何在 SVG 中包含 jQuery SVG 源?

javascript - 需要帮助 : RegEx for a password containing numbers and special chars