013-004-008

Pattern Search with Pattern Class

Medium

Problem Description

Pattern Search with Pattern Class

In this problem, you will create a program that reads a line of text from standard input, searches and extracts all mobile phone numbers using regular expressions, and displays the results to standard output.

Learning Objective: Understand advanced regex processing using Pattern and Matcher classes

Overview

Create a program that uses Pattern and Matcher classes to search and extract all phone number patterns from an input string.

Specifications

  • Read one line from standard input and store it in string text
  • Use regex pattern "0[89]0-[0-9]{4}-[0-9]{4}" (mobile phone number pattern)
  • Compile the pattern with Pattern.compile()
  • Search for all matches in the string with Matcher.find()
  • Output all found phone numbers (output nothing if no matches)

Input

A single line of text to search

Output Format

Output each matched phone number on its own line.

Example (input: Call 090-1234-5678 or 080-9876-5432 for info.):

090-1234-5678
080-9876-5432

Ready to Try Running Code?

Log in to access the code editor and execute your solutions for this problem.

Don't have an account?

Sign Up