Friday, January 8, 2016

Re: Find adjacent lines starting with same pattern

On 2016-01-08 03:14, Yannick Schall wrote:
> body {
> margin: 10px;
> padding: 10px;
> padding: 20px;
> background: #fff;
> }
>
> I can find duplicated lines with:
> /^\(.*\)\n\1$
>
> I can match and capture the properties on every lines:
> \S\{-}:\)
>
> I can match the whole line and capture the properties and value:
> \(\S\{-}:\)\(.\{-};\)
>
> But if i try to to apply the pattern on the next line ( \n\1 ) it
> doesn't match anything: \(\S\{-}:\)\(.\{-};\)\n\1

You'd have to have the spacing the same too. To be more forgiving
of varying spacings, try

^\s*\([^:]\{-}\)\s*:.*\n\s*\1\s*:

\s* optional space
\([^:]\{-}\) capture as few things that aren't a colon (the prop)
\s* optional space
: the literal colon
.* the value to be discarded
(you can capture this if you care)
\n the newline
\s* optional leading whitespace
\1 the same attribute we matched before
\s* optional whitespace
: a colon

I anchored it at the second colon to ensure that things like

background: border-box red;
background-color: yellow;

doesn't match as a duplicate.

-tim





--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments: