New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

正規表現: \v,\V と パターンの先頭,末尾の対応が一貫してない #557

Closed
haya14busa opened this Issue May 6, 2014 · 10 comments

Comments

Projects
None yet
6 participants
@haya14busa
Member

haya14busa commented May 6, 2014

再現スクリプト

" パターン末尾
echo '=================='
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 <- おかしい?

" パターン先頭
echo '=================='
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

" 括弧なしでも再現
echo '=================='
echo 'hoge' =~# 'hoge$\v'       | " Expect 1, Result 0 <- おかしい?
echo 'hoge' =~# 'hoge$\V'       | " Expect 1, Result 0 <- おかしい?
echo 'hoge' =~# 'hoge$\m'       | " Expect 1, Result 1
echo 'hoge' =~# 'hoge$\M'       | " Expect 1, Result 1

echo '=================='
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

$ はヘルプの記載によると

パターンの末尾、または "|"、")"、"\n" ('magic' on時) の前にある場合、行末 () にマッチします

と書かれており、^

パターンの先頭にある場合、行頭にマッチします。"|"、"("、"%(" の直後でも構いません。

と書かれています。

この"\|""\)"\vといったマジックフラグを前置してもOKだとすれば、echo 'hoge' =~# '\(hoge$\v)' の結果が0なのは不自然かと思います。 また、\mを使えば期待した結果通りになります

NFAは1でも2でも再現しました。

一応Lingrのログ: http://lingr.com/room/vim/archives/2014/05/06#message-18949545

@mattn

This comment has been minimized.

Member

mattn commented May 7, 2014

echo 'hoge' =~# '\(hoge$\v)'    | " Expect 1, Result 0 <- おかしい?

\) でないのは意図的ですか?

@thinca

This comment has been minimized.

Member

thinca commented May 7, 2014

\v なので ) ですね。

@mattn

This comment has been minimized.

Member

mattn commented May 7, 2014

あーそういう issue なのか

@ichizok

This comment has been minimized.

Member

ichizok commented Jun 5, 2014

@haya14busa

This comment has been minimized.

Member

haya14busa commented Jun 26, 2014

(反応遅くてスイマセン...)

@ichizok さんのパッチを試したところ期待する動作になりました!

@h-east

This comment has been minimized.

Member

h-east commented Jun 27, 2014

@ichizok Please send patch. 👍

@ichizok

This comment has been minimized.

Member

ichizok commented Jul 2, 2014

@haya14busa

This comment has been minimized.

Member

haya14busa commented Jul 2, 2014

ありがとうございます! @ichizok さん++ 👍

@k-takata

This comment has been minimized.

@haya14busa

This comment has been minimized.

Member

haya14busa commented Jul 10, 2014

@ichizok さんありがとうございました! 💯

haya14busa added a commit to haya14busa/incsearch.vim that referenced this issue Aug 9, 2014

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment