2
2

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 3 years have passed since last update.

GASでスクレイピングしたデータからmatchメソッドで必要な情報を抜き出す

Posted at

GASの正規表現はいろいろあるけど、
とりあえず基本の方法を2種類だけ自分用備忘録として残します。

GASでGmailから、getPlainBody() で、以下のように取得したとする。

タイトル:再エネを活用したEVタクシーで「地域MaaS」
浜松市佐久間町で実証へ
記事URL:https://www.kankyo-business.jp/news/026013.php

ここからタイトル、記事URLを抜き出すには、

タイトルは複数行にわたるので、
\s([\s\S]*)
を使う

urlは1行ですむので、
(.*)

つまり、

コード.gs
let title = plainBody.match(/タイトル:\s([\s\S]*)記事URL:/);
let url =   plainBody.match(/記事URL:(.*)/);

2
2
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
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?