Yakov Lerner wrote:
On 8/11/06, Brian Anderson <[EMAIL PROTECTED]> wrote:
Hello,
I'm working with some plain text files, to prepare them for LaTeX. I'm
trying to search for a whole line of text, then put it into brackets.
for the text:
3.0 some words in the line
I want to replace it with:
\subsection{some words in the line}
There is a tab between the last digit and the first word, and one or
more spaces between words.
So far I've come up with:
s/\d.\d\t\(\a*\s\?\a*\)/\\subsection{\1}/
This works, but only if there is one word followed by one space followed
by one word.
s/\d.\d\t\(\a.*)/\\subsection{\1}/
Yakov
A period in a search pattern means "anything"; to match a dot, use '\.'.
To replace any number of dot-separated numbers followed by any number of
spaces or tabs, use
s/^\%(\d\+\.\)*\d\+\s\+\(.*\)$/\\subsection{\1\}/
which means:
s/ replace what?
^ start of line
\%( start a sub-pattern here but don't count it as \1
\d a digit
\+ repeated one or more times
\. a dot
\) close sub-pattern
* the sub-pattern is repeated zero or more times
\d a digit
\+ repeated one or more times
\s a space or tab
\+ repeated one or more times
\( start a sub-pattern here and count it as \1
. any character, but not a line break
* repeated zero or more times
\) end of sub-pattern
$ end of line
/ replace by what?
\\ a backslash
{ a left brace
\1 the text matching sub-pattern \1 above
} a right brace
/ end of "replace by" part
Prefix this by 3,25 to replace from line 3 to line 25; by % or 1,$ to
replace in the whole file; by '<,'> to replace in the latest visual
area; etc. With no prefix it replaces in the current cursor line.
See
:help :s
:help /pattern-overview
:help sub-replace-special
Best regards,
Tony.