文章から拾う

会社のページの番号を一覧にする

extractdigits
TEL と FAX の番号を拾い、表記の違う重複を除きます。
試す
  • 03-5253-8111
  • 03-5253-8112
  • 092-513-5612

しくみ

ページには、同じ番号が国内向けと国際形式で2回書かれていることがよくあります。digits をキーにすると、1つの番号を1回だけ残せます。

extract は TEL と FAX を区別しません。区別が必要なら、番号の直前の言葉を自分のコードで読みます。

各言語で

import { extract } from "@kurashina-design/japan-phone";

// The contact section of a company page. The same number appears twice in different notations.
const page = `本社 TEL 03-5253-8111 / FAX 03-5253-8112
From overseas: +81-3-5253-8111
福岡支店 TEL 092-513-5612`;

const unique = new Map();
for (const number of extract(page)) unique.set(number.digits, number);
for (const number of unique.values()) console.log(number.national);

出力:

03-5253-8111
03-5253-8112
092-513-5612