9
6

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][Node.js] 配列を正規表現でフィルタする

Last updated at Posted at 2018-01-25

JavaScript の配列の中身を正規表現にマッチした要素のみにフィルタする方法です。

filter-sample.js
let original_array = new Array('A', 'B', 'C');
let filtered_array = original_array.filter(function(value) { return value.match(/pattern/); });

例えば、XLSXファイルにて、testcaseで始まるシート名の配列を得るには次のようにします。
(XLSXファイルの解析には xlsx モジュールを利用しています)

xlsxsheet-filter-sample.js
const xlsx  = require('xlsx');
let workbook = xlsx.readFile('sample.xlsx');
let testcase_sheetnames = workbook.SheetNames.filter(function(value) { return value.match(/^testcase.*$/); });
9
6
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
9
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?