Try this:
String x = "Hello (Java)";
Matcher m = Pattern.compile("\\((.*?)\\)").matcher(x);
while (m.find()) {
System.out.println(m.group(1));
}
or
String str = "Hello (Java)";
String answer = str.substring(str.indexOf("(")+1, str.indexOf(")"));
More Related Contents:
- Find the highest number between two literal strings using a Regular Expression
- How to split a string, but also keep the delimiters?
- Match multiline text using regular expression
- Regex to match a C-style multiline comment
- Regex for matching something if it is not preceded by something else
- Splitting a string at every n-th character
- Parsing XML with REGEX in Java
- Java – Best way to grab ALL Strings between two Strings? (regex?)
- removing invalid XML characters from a string in java
- Replacing all non-alphanumeric characters with empty strings
- Extracting pairs of words using String.split()
- Java – regular expression finding comments in code
- Remove all empty lines
- Given a string, generate a regex that can parse *similar* strings
- Regular Expression to match 3 or more Consecutive Sequential Characters and Consecutive Identical Characters
- How to split a comma separated String while ignoring escaped commas?
- PatternSyntaxException: Illegal Repetition when using regex in Java
- java regex capture group
- How to remove HTML tag in Java [duplicate]
- Split string into sentences
- What is the equivalent of Regex-replace-with-function-evaluation in Java 7?
- Regex split numbers and letter groups without spaces
- Why does replaceAll fail with “illegal group reference”?
- How to create a regex for accepting only alphanumeric characters? [duplicate]
- Java String ReplaceAll method giving illegal repetition error?
- Find all words with 3 letters with regex
- String.replaceAll is considerably slower than doing the job yourself
- Remove all occurrences of \ from string
- Extract ip addresses from Strings using regex
- Validate if input string is a number between 0-255 using regex