- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Java Program to split a string using Regular Expression
Let’s say we have the following string.
String str = "{Java is a programming language} {James Gosling developed it.}";
Above, the string is enclosed with parentheses. We can split a string with these parentheses using the split() method.
String[] strSplit = str.split("[{}]");
The following is an example.
Example
public class Demo { public static void main(String[] args) throws Exception { String str = "{Java is a programming language} {James Gosling developed it.}"; String[] strSplit = str.split("[{}]"); System.out.println("Splitting String..."); for (int i = 0; i < strSplit.length; i++) System.out.println(strSplit[i]); } }
Output
Splitting String... Java is a programming language James Gosling developed it.
Advertisements