6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Googleスプレッドシートの正規表現で先読み後読みが使えない問題をなんとかした

Last updated at Posted at 2018-07-10

Googleスプレッドシートの正規表現で先読み後読みが使えない問題をなんとかした

はじめに

コメントアウトを検出するために正規表現を使いましたが、Cの#defineまで引っかかったので否定先読みを試みたらエラーが表示されました。調べてみるとサポートしていなかったようで、それをなんとかした話です。

https://github.com/google/re2/blob/master/doc/syntax.txt#L82-L85

(?=re)	before text matching «re» NOT SUPPORTED
(?!re)	before text not matching «re» NOT SUPPORTED
(?<=re)	after text matching «re» NOT SUPPORTED
(?<!re)	after text not matching «re» NOT SUPPORTED

やったこと

エラー

否定先読みがサポートされていないので失敗

=REGEXMATCH("#define HOST 192.168.1.10", "(?!#define)#")

=> エラー
関数 REGEXMATCH のパラメータ 2 の値「(?!#define)#」は無効な正規表現です。

成功

否定先読みの部分をREGEXREPLACEで置換すればいけそうです。

=REGEXMATCH(REGEXREPLACE("#define HOST 192.168.1.10","#define",""), "#")
=> FALSE

=REGEXMATCH(REGEXREPLACE("#server_address=192.168.1.1","#define",""), "#")
=> TRUE

6
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?