Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Below are the String values I want to separate the inside brackets value
US Records (100)
Foreign Records (243)
In the string above I want to separate the counts and store into another string
100, 243 using regular expression.
This code schold give you the result:
String s = new String("US Records (100)");
Pattern p = Pattern.compile("\\((\\d+)\\)");
Matcher m = p.matcher(s);
m.find();
System.out.println(m.group(1));
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
How do I get the after last two semicolon's occurrences of a string ?
Example:
Mobiles;Students;Test;Yes;1234
The output should be
Yes;1234
Using a regex replacement, we can try:
String input = "Mobiles;Students;Test;Yes;1234";
String output = input.replaceAll("^.*;([^;]+;[^;]+)$", "$1");
System.out.println(output); // Yes;1234
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I have JSON response from server. JSON has exception info inside of it.
I need to parse it to detect that exception occurred and identify which one.
JSON example:
I found the solution to what I need
Pattern errorCodePattern = Pattern.compile("\"code\"\\s*:\\s*\"([^,]*)\",");
Pattern messagePattern = Pattern.compile("\"message\"\\s*:\\s*\"([^,]*)\",");
Pattern statusPattern = Pattern.compile("\"status\"\\s*:\\s*\"(FAILURE)\"");
Matcher errorCodeMatcher = errorCodePattern.matcher(response);
Matcher messageMatcher = messagePattern.matcher(response);
Matcher statusMatcher = statusPattern.matcher(response);
Java JSON Parser Example with Regex
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
how can I alter text string fields in java to only contain certain alphabetical characters (f,-)
in this format: 2f5-4, 2f6, 8f9
Only numbers f numbers and
numbers f number - numbers
You could use a regular expression to check, if the String in your text field is valid:
\d+f\d+(?:-\d+)?
Java code sample
Pattern pattern = Pattern.compile("\\d+f\\d+(?:-\\d+)?");
for (String s : new String[] {
"2f6", "2f9", "6f10", "5f9-2", "3f4-9"
}) {
System.out.println("String: \""+s+"\" match: "+pattern.matcher(s).matches());
}
Regex expression =>
(([0-9]+)([f])([0-9]*)|(([-])([0-9]*)))\w+
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a function:
ItemValue[i] = substring(toString(obj),0,toString(obj).indexOf(".") + 4);
where obj is a number. The function works for 9,999,999.99999 -> 9999999.999 but values such as 99,999,999.99999 gets converted to 9.999.
Is it a data type issue?
Thanks,
The problem is with the double values you are using. The value 99999999.99999 will be translated to 9.999999999999E7 by toString() so the results you are getting. In order to strip the digits after decimal you can use DecimalFormat class:
DecimalFormat f = new DecimalFormat();
f.setMaximumFractionDigits(3);
f.setMinimumFractionDigits(3);
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 9 years ago.
Improve this question
I have this text:
1 A Maths
And i would like to get only Maths.
I donĀ“t know about regular expressions.
Can any one help me, please?
Thanks
Why don't you split the string ?
String chain="A Maths";
String[] array=chain.split(" ");
String number=array[0];
String course=array[1];
...
How to split a string in Java