Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Goの標準パッケージregexpが先読みに対応していない件

Avatar for yamatai12 yamatai12
October 28, 2025

 Goの標準パッケージregexpが先読みに対応していない件

Avatar for yamatai12

yamatai12

October 28, 2025
Tweet

More Decks by yamatai12

Other Decks in Technology

Transcript

  1. regexpはRE2の記法に従う https://pkg.go.dev/regexp it is the syntax accepted by RE2 and

    described at https://golang.org/s/re2syntax RE2は先読みをサポートしていない (?=re) before text matching re (NOT SUPPORTED) (?!re) before text not matching re (NOT SUPPORTED) RE2のアルゴリズムは入力文字列の長さに比例した時間で実行される 8
  2. RE2はなぜ先読みに対応していないのか? 理由) 先読みに対応すると検索が遅くなる 先読みは指数関数的な実行時間を要するため RE2 doesn't support lookahead, positive or

    negative, since it would requires an algorithm with worst-case exponential running time. https://groups.google.com/g/re2j-discuss/c/02Wzz-v2Flo 9