如何找到一个模式上线3号发生 [英] How to find the 3rd occurrence of a pattern on a line

查看:173
本文介绍了如何找到一个模式上线3号发生的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

今天,我不得不对齐表格的一行只有第一多个空格。

Today I had to align a table at only the first multiple spaces on a line.

体育教育。

<ScrollWheelDown>    move window     three lines     down  
<S-ScrollWheelDown>     move window    one page   down
<ScrollWheelUp>        move window      three lines up
<S-ScrollWheelUp>    move window   one page      up

我用表格插件来调整表,但我不能找到一种方法如何找到多个空格,只有第一次出现,做一个对齐只有在那里。

I use Tabular plugin to align tables but I could not find a way how to find only the first occurrence of multiple spaces and do an align only there.

我不知道它无论是在VIM: 将正则表达式如果我只是想找到一个线路上的图案第三发生? 是正则表达式与使用表格?

I don't know it either in VIM: What will be the regex if I only want to find the 3rd occurrence of a pattern on a line? Is the regex the same as using Tabular?

推荐答案

正则表达式是:

/\(.\{-}\zsPATTERN\)\{3}

所以,如果,例如,要在3'富'更改为'巴'以下行:

So if, for example, you want to change the 3rd 'foo' to 'bar' on the following line:

lorem ifoopsum foo lor foor ipsum foo dolor foo
       ^1      ^2      ^3         ^4        ^5

运行:

s/\(.\{-}\zsfoo\)\{3}/bar/

获得:

lorem ifoopsum foo lor barr ipsum foo dolor foo
       ^1      ^2      ^3=bar     ^4        ^5

这篇关于如何找到一个模式上线3号发生的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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