013-004-002
Regex Pattern Class: Pattern and Matcher
Hard
Problem Description
Regex Pattern class: Pattern and Matcher
In this problem, you will create a program that searches for and extracts phone number patterns (XXX-XXXX-XXXX) from input text using the Pattern and Matcher classes, and displays the results to standard output.
Learning Objective: Understand how to perform regex matching using Pattern and Matcher classes
Overview
Extract phone number patterns (XXX-XXXX-XXXX) from the input string.
Specifications
- Compile pattern using Pattern.compile()
- Get matcher using matcher()
- Search for pattern match with find()
- Get matched string with group()
Input
Text containing phone numbers is provided
Output Format
Found: 090-1234-5678
Found: 080-9876-5432
Test Cases
※ Output examples follow programming industry standards
Input:
Call me at 090-1234-5678 or 080-9876-5432
Expected Output:
Found: 090-1234-5678 Found: 080-9876-5432
Input:
My number is 070-1111-2222
Expected Output:
Found: 070-1111-2222
Input:
Call me at 090-1234-5678 or 080-9876-5432
Expected Output:
Found: 090-1234-5678 Found: 080-9876-5432
Input:
Call me at 090-1234-5678 or 080-9876-5432
Expected Output:
Found: 090-1234-5678 Found: 080-9876-5432
❌ Some tests failed
Your Solution
Current Mode:● My Code
99
1
2
3
4
5
6
7
8
9
10
›
⌄
⌄
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
// Write your code here
sc.close();
}
}
0 B / 5 MB
You have 6 free executions remaining
