Regexp 'very (no) magic' flags do erratic behavior

52 views
Skip to first unread message

Ozaki Kiichi

unread,
Jul 2, 2014, 2:57:09 PM7/2/14
to vim...@googlegroups.com
Hi.

In regexp operation,
\v and \V, in contrast with \c, \C, \m and \M, disable the preceding '$' (end-of-line) atom.
This seems to be inconsequence.


" matching end-of-line
echo 'hoge' =~# 'hoge$\m' | " Expect 1, Result 1
echo 'hoge' =~# 'hoge$\M' | " Expect 1, Result 1
echo 'hoge' =~# 'hoge$\v' | " Expect 1, Result 0 <- ?
echo 'hoge' =~# 'hoge$\V' | " Expect 1, Result 0 <- ?

" matching start-of-line
echo 'hoge' =~# '\v^hoge' | " Expect 1, Result 1
echo 'hoge' =~# '\V\^hoge' | " Expect 1, Result 1
echo 'hoge' =~# '\m^hoge' | " Expect 1, Result 1
echo 'hoge' =~# '\M^hoge' | " Expect 1, Result 1

" with parentheses
" end-of-line
echo 'hoge' =~# '\(hoge$\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(hoge$\m\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(hoge$\M\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(hoge$\c\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(hoge$\C\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(hoge$\v)' | " Expect 1, Result 0 <- ?
echo 'hoge' =~# '\(hoge$\V\)' | " Expect 1, Result 0 <-?

" start-of-line
echo 'hoge' =~# '\(^hoge\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(\v^hoge)' | " Expect 1, Result 1
echo 'hoge' =~# '\(\V\^hoge\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(\c^hoge\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(\C^hoge\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(\m^hoge\)' | " Expect 1, Result 1
echo 'hoge' =~# '\(\M^hoge\)' | " Expect 1, Result 1


https://gist.githubusercontent.com/ichizok/ff37b16576321b287b0d/raw/d12eced50f1cdc2b7dcf7648814fd095d931d0a1/regexp-magic-all-after-eol.patch

This patch checks the existence of \v and \V after '$', and sets 'magic_all' temporarily.

Thanks.
- Ozaki Kiichi

Bram Moolenaar

unread,
Jul 2, 2014, 4:47:21 PM7/2/14
to Ozaki Kiichi, vim...@googlegroups.com
Thanks, I'll add it in the todo list.

--
FATHER: We are here today to witness the union of two young people in the
joyful bond of the holy wedlock. Unfortunately, one of them, my son
Herbert, has just fallen to his death.
[Murmurs from CROWD; the BRIDE smiles with relief, coughs.]
"Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD

/// Bram Moolenaar -- Br...@Moolenaar.net -- http://www.Moolenaar.net \\\
/// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\ an exciting new programming language -- http://www.Zimbu.org ///
\\\ help me help AIDS victims -- http://ICCF-Holland.org ///

Ben Fritz

unread,
Jul 2, 2014, 10:59:53 PM7/2/14
to vim...@googlegroups.com
On Wednesday, July 2, 2014 1:57:09 PM UTC-5, Ozaki Kiichi wrote:
> Hi.
>
> In regexp operation,
> \v and \V, in contrast with \c, \C, \m and \M, disable the preceding '$' (end-of-line) atom.
> This seems to be inconsequence.
>
>
> " matching end-of-line
> echo 'hoge' =~# 'hoge$\m' | " Expect 1, Result 1
> echo 'hoge' =~# 'hoge$\M' | " Expect 1, Result 1
> echo 'hoge' =~# 'hoge$\v' | " Expect 1, Result 0 <- ?
> echo 'hoge' =~# 'hoge$\V' | " Expect 1, Result 0 <- ?
>

Shouldn't you need to escape the $ with a \ when using \V?

Павлов Николай Александрович

unread,
Jul 3, 2014, 12:49:38 AM7/3/14
to vim...@googlegroups.com, Ben Fritz
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512
\V only *starts* the region. It does not affect the whole pattern.
-----BEGIN PGP SIGNATURE-----
Version: APG v1.1.1

iQI1BAEBCgAfBQJTtODWGBxaeVggPHp5eC52aW1AZ21haWwuY29tPgAKCRCf3UKj
HhHSvoe0EACj7eDSj+L2z+fwjssHRsapopQL5YZmhUqrY9Rym+RHEzrMsF07WmyA
Zzl4zO7fBm1XCuIe1enA2pRI4Udy6Sq0XurfhOpHcqiePfwBcJqYG3QZqPWrX4nG
A/hZefHGAN63LCH37RJubpzEkrJ6x4CIpEbNVsSvgmylTr99NV6IKcLwAX/1hM1R
uGurE8R6BSSgps0g8TqdHMwwRw/dOP4NvOEu3OO5s33iTRNLv81JXm77gP5qe9Dl
17lkeCtHTCYrmJ95ULGnKapJ7FFx2OXW5U3VCSboKUXn9eBaw9DKbUOi6Atzvsnt
hThHxJsBUu4fiDrnWnR09O9Aqh87Zfu1gPQqCeCfdNC1OUZNWQMVf2LKLj7Nt2IW
sb9iSyPWBszQatz6MKDzT/iAfJhBWAolEAHHA26SjYuPbe4ErJzt48lApo2az6Li
b8T+PSloHU/Z5CY+IlrPzoNUKFmBP7SYOKcLi3Hu1NCYLV09sHdfnRPf7So96sy8
AzshC84gXfFuGfk0mHW4Xoy+XsBte9mFTxPjlpBz5tFTqtnqIwG2q3WyD1cXlhKK
7rVy0vQyw+hwn+QPExpwDJeD81E3C7kJpD2lK0/gBr/VY1y2qGq8J5dJPoJgAtkc
iQGkOpAmxnV8DAlhHr2KZy6gr9zv8wMfaa/PQWAzpK4mUYwHKYCNJQ==
=fQA/
-----END PGP SIGNATURE-----

Ben Fritz

unread,
Jul 3, 2014, 1:07:38 AM7/3/14
to vim...@googlegroups.com, fritzo...@gmail.com
On Wednesday, July 2, 2014 11:49:38 PM UTC-5, ZyX wrote:
> >Shouldn't you need to escape the $ with a \ when using \V?
>
> \V only *starts* the region. It does not affect the whole pattern.
>

Ah, you're right. I was expecting it to act like \c and \C:

*/\c* */\C*
When "\c" appears anywhere in the pattern, the whole pattern is handled like
'ignorecase' is on. The actual value of 'ignorecase' and 'smartcase' is
ignored. "\C" does the opposite: Force matching case for the whole pattern.
{only Vim supports \c and \C}

Reply all
Reply to author
Forward
0 new messages