如何使用Vim提取与正则表达式匹配的文本? [英] How to extract text matching a regex using Vim?

查看:297
本文介绍了如何使用Vim提取与正则表达式匹配的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用vim从文本中提取一些数据. 数据是这样的:

I would like to extract some data from a text with vim.. the data is of this kind:

72" title="(168,72)" onmouseover="posizione('(168,72)');" onmouseout="posizione('(-,-)');">>
72" title="(180,72)" onmouseover="posizione('(180,72)');" onmouseout="posizione('(-,-)');">>
72" title="(192,72)" onmouseover="posizione('(192,72)');" onmouseout="posizione('(-,-)');">>
72" title="(204,72)" onmouseover="posizione('(204,72)');" onmouseout="posizione('(-,-)');">>

我需要提取的数据包含在:title =(168,72)".
特别是我只想提取这些坐标.

The data I need to extract is contained in: title="(168,72)".
In particular I am interested in extracting only these coordinates.

我虽然打算先用vim删除 title ="之前的所有内容.但是我并不是真正的正则表达式专家.所以我问你:是否有人有任何提示:请告诉我:)

I though about using vim to first delete everything before title=" .. but I am not really a guru of regex.. so I am asking you: if anyone has any hint: please tell me :)

推荐答案

这将用制表符分隔的每行坐标列表替换每行:

This will replace each line with a tab-delimited list of coordinates per line:

:%s/.* title="(\(\d\+\),\(\d\+\))".*/\1\t\2

这篇关于如何使用Vim提取与正则表达式匹配的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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