Atomic Habits

vim 정규식(전방탐색 후방탐색) 본문

IT/Regular Expressions

vim 정규식(전방탐색 후방탐색)

체계성 2022. 5. 27. 10:34

VIM 정규식
전방탐색/후방탐색
긍정형/부정형

(?=) : \(\)\@=     : 긍전
(?<=) : \(\)\@<=   : 긍후
(?!) : \(\)\@!     : 부전
(?<!) : \(\)\@<!   : 부후


3(?=천)
1000원, 3천원, 33원  >>>  /3\(천\)\@=  >>>  1000원, [3]천원, 33원

(?<=천)원
1000원, 3천원, 33원  >>>  /\(천\)\@<=원  >>>  1000원, 3천[원], 33원

3(?!천)원
1000원, 3천원, 33원  >>>  /3\(천\)\@!원  >>>  1000원, 3천원, 3[3원]

(?<!천)원
1000원, 3천원, 33원  >>>  /\(천\)\@<!원  >>>  1000[원], 3천원, 33[원]

 

 

\(foo \)\@<=bar\( baz\)\@= matches the “bar” in foo bar baz.

But the lookaround groups are still required, so it doesn't match at all for foo bar qux or foo bar or foo.
(foo )@<=bar( baz)@= in very magic mode.
\(mi \)\@<=casa matches “casa” if preceded by “mi ”. So it matches only the first “casa” in mi casa es su casa.
\(mi \)\@<!casa matches “casa” if not preceded by “mi ”. So it matches only the second “casa” in mi casa es su casa.
dad\(\.\)\@= matches “dad” if followed by a period.

So it matches only the second “dad” in My dad is bigger than your dad.
dad\(\.\)\@= matches “dad” if not followed by a period.

So it matches only the first “dad” in My dad is bigger than your dad.

 

ex) 

foo bar baz.
foo bar qux.
foo bar or foo.
mi casa es su casa.mi casa es su casa.
My dad is bigger than your dad.
My dad is bigger than your dad.

 

Comments