On 08/17/12 07:46, Paul Anton Letnes wrote:
> this is possibly me not being regex proficient enough, but here
> goes: When I search for patterns with 'not newline' at the end,
> for instance, "/&[^\n]", the "[ ]" part seems to match "/&\n". I
> have realized that using simply "/&." is a simpler and better
> regex, but nevertheless - why doesn't my first suggestion work as
> expected?
I was a little surprised by this one. Starting with a "-u NONE" vim,
I ":set hls" and issued
/r[^\n]
which should have found all the "r" characters in my text that
weren't at the end of the line. Yet, as Paul notes, it found "r"
characters at the end of a line. Curious whether it needed to allow
newlines (":help /[\n]") to exclude them, I tried changing the
pattern to
/r\_[^\n]
to no avail. It does seem to recognize at least *some* backslash
escapes, as trying it with "/[\t]" and "/[^\t]" seem to behave as
expected. Likewise, searching for "/r[\n]" correctly behaves like
"/r$" does.
I do know that character-class escapes don't work in Vim like they
do in Perl/Python ("/[-\w]" to find "\w"ord characters or a minus sign).
> Furthermore, I notice (using the hlsearch option) that the
> pattern [\n] matches _everything_. This must surely be a bug?
I don't see this one happening. All I see is the last+1 character
highlighted, which makes sense to me. Vim 7.2.445, in case it matters.
-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
Friday, August 17, 2012
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment