Split String by Digits
This program splits string by digits using regex.
Problem Statement
Write a Java program to split string by digits.
Source Code
| 1 | public class RegexSplit { |
| 2 | public static void main(String[] args) { |
| 3 | System.out.println("Eduinq Regex Split"); |
| 4 | String str="Eduinq123Test456"; |
| 5 | String[] parts=str.split("\\d+"); |
| 6 | for(String p:parts) System.out.println(p); |
| 7 | } |
| 8 | } |
Program Output
Eduinq Regex Split Eduinq Test
Explanation
The regex \d+ matches one or more consecutive digits, and the split() method divides the string at these matches, demonstrating a regex-based string split.