LoginSignup
1
1

More than 1 year has passed since last update.

javascriptでの正規表現を用いて文字列を抽出する方法

Last updated at Posted at 2022-04-12

業務でjsから文字列を抽出する作業を何度か行った為、
忘備録を残しておく。

例:

ex.js
var a = "抽出元の文字列";
var b = a.match(/正規表現/);
console.log(b);//正規表現にマッチする文が出力

グルーピングを用いることも可能
阿部寛のホームページから「abehiroshi」のみを抽出する場合

abe.js
var url = "http://abehiroshi.la.coocan.jp/";
var i = url.match(/(abe.*?)\./);
console.log(i[1]);//abehiroshi
1
1
3

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