Finding numbers in text
List the numbers on a company page
extractdigits
Find TEL and FAX numbers and drop duplicates written in other notations.
Try it
03-5253-811103-5253-8112092-513-5612
How it works
A page often shows the same number twice: once for domestic callers and once in international form. Use digits as the key to keep each number once.
extract does not tell TEL from FAX. When you need that, read the words just before each number in your own code.
In each language
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);
from japan_phone import extract
# The contact section of a company page. The same number appears twice in different notations.
page = """本社 TEL 03-5253-8111 / FAX 03-5253-8112
From overseas: +81-3-5253-8111
福岡支店 TEL 092-513-5612"""
unique = {number.digits: number for number in extract(page)}
for number in unique.values():
print(number.national)
import jp.kurashina.japanphone.JapanPhoneNumber;
import jp.kurashina.japanphone.JapanPhone;
import java.util.LinkedHashMap;
import java.util.Map;
// The contact section of a company page. The same number appears twice in different notations.
String page = "本社 TEL 03-5253-8111 / FAX 03-5253-8112\n"
+ "From overseas: +81-3-5253-8111\n"
+ "福岡支店 TEL 092-513-5612";
Map<String, JapanPhoneNumber> unique = new LinkedHashMap<>();
for (JapanPhoneNumber number : JapanPhone.extract(page)) unique.put(number.getDigits(), number);
for (JapanPhoneNumber number : unique.values()) System.out.println(number.getNational());
Output:
03-5253-8111
03-5253-8112
092-513-5612