28
16

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.

[javascript]URLを取得する正規表現

Posted at

今後も何かで使いそうなのでメモ。
http://example.com?keyword=hogehoge&limit=25
のようなクエリパラメータにも対応してます。

  • 英字のみのURL
/https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#]+/g
  • 日本語を含むURL
/https?:\/\/[-_.!~*\'()a-zA-Z0-9;\/?:\@&=+\$,%#\u3000-\u30FE\u4E00-\u9FA0\uFF01-\uFFE3]+/g

でいける。ちなみにimgタグなどの画像のURLを取得したい場合は

/(src=)["|'](.*?)["|']+/g

でsrcの部分だけ先に取得して上記のURLの正規表現をとってこればいけるはず。

28
16
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
28
16

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?