Finding numbers in text
Find numbers in a message
extract
Pick every phone number out of a message, in the order it appears.
Try it
090-1234-5678092-513-5612
How it works
extract searches free text and returns one result per number, in the order found. Each result has the same fields as normalize.
- Any text may surround a number: Japanese words, punctuation, names, line breaks.
- Digit strings that do not fit the numbering plan or the MIC tables, such as dates, are not returned. Other digit strings, such as order numbers, are returned when they have the length of a phone number and happen to fall in a valid block.
- The same number written twice is returned twice. See the company page example to remove duplicates.
In each language
import { extract } from "@kurashina-design/japan-phone";
// A message from a contact form.
const message = "お世話になっております。日中は090-1234-5678、夜は自宅の092-513-5612までご連絡ください。";
for (const number of extract(message)) console.log(number.type, number.national);
from japan_phone import extract
# A message from a contact form.
message = "お世話になっております。日中は090-1234-5678、夜は自宅の092-513-5612までご連絡ください。"
for number in extract(message):
print(number.type, number.national)
import jp.kurashina.japanphone.JapanPhoneNumber;
import jp.kurashina.japanphone.JapanPhone;
// A message from a contact form.
String message = "お世話になっております。日中は090-1234-5678、夜は自宅の092-513-5612までご連絡ください。";
for (JapanPhoneNumber number : JapanPhone.extract(message)) {
System.out.println(number.getType() + " " + number.getNational());
}
Output:
mobile 090-1234-5678
fixed_line 092-513-5612