12
8

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.

URLパラメータ文字列から値を取得する正規表現

Posted at

&で分割して=で分割するような PHPだと、parse_str() を使うような場面で、
JavaScriptや Nginxのconfファイル内でマッチさせるときなど、正規表現が良かったりします。

正規表現でパラメータの値を取得する

/name=(.*?)(&|$)/

ポイント

  • 最小マッチとするため (.*?) はてなをつけるところ
  • 値の次に続くのは (&|$)。パラメータの区切り文字である「&」または終端を表す「$」 のいずれか。

詳しくは
http://did2memo.net/2015/12/28/javascript-url-parameter/

12
8
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
12
8

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?