Skip to content
New issue

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

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

Already on GitHub? # to your account

問題 147 で grep -Pgrep -z の組み合わせがうまく動かない #52

Closed
norioxkimura opened this issue Sep 4, 2022 · 5 comments

Comments

@norioxkimura
Copy link

norioxkimura commented Sep 4, 2022

printf '<td>\ncell</td>\n' | grep -zoP '<td[^<]*>.*?</td>' を実行しても何も表示されない(行をまたいだ <td>...</td> にマッチしない)。man grep には -P-z の組み合わせは experimental と書いてある。

Ubuntu 20.04, grep 3.4, libpcre 3.13.3

@ryuichiueda
Copy link
Contributor

こちら対応おそくなってすみません。週末対応します。

@ryuichiueda
Copy link
Contributor

ryuichiueda commented Sep 20, 2022

これは間違いといいますか、念の為が念の為になっていないので、-Eのほうがいいですね(ちょっとご都合主義ですが)。修正しておきます。ありがとうございました。

@ryuichiueda
Copy link
Contributor

メモ:

  • 問題147はgrep -zoPが改行に対応していない
  • 練習3.2.aではgrep -ozPが機能する

@ryuichiueda
Copy link
Contributor

ryuichiueda commented Sep 20, 2022

ebanさんから。「PCREだと改行が.にマッチしない」というのが理由とのこと。-Pをつかったまま修正するなら↓。

printf '<td>\ncell</td>\n' | grep -zoP '(?s)<td[^<]*>.*?</td>'

@ryuichiueda
Copy link
Contributor

ryuichiueda commented Sep 20, 2022

↑ということで、ライブラリのバージョン違いと言うよりは、本書の記述の単なる間違いでした。しばらくしたら閉じます。

ありがとうございました。

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants