- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
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.
- Related Articles
- How to Split String in Java using Regular Expression?
- Program to match vowels in a string using regular expression in Java
- How do we use a delimiter to split string in Python regular expression?
- How to split a string using regular expressions in C#?
- Java Regular expression to check if a string contains alphabet
- How to split on successions of newline characters using Python regular expression?
- How to extract each (English) word from a string using regular expression in Java?
- How to print all the characters of a string using regular expression in Java?
- Java Program to split a string with dot
- Java program to split and join a string
- How to match digits using Java Regular Expression (RegEx)
- Moving all special char to the end of the String using Java Regular Expression RegEx)
- How to match a regular expression against a string?
- Java Regular Expression that doesn't contain a certain String.
- How to match non-digits using Java Regular Expression (RegEx)

Advertisements