I have the following String input.
String s = "I have 5000 bananas";
I am extracting the numeric value using a regex String regex = "\\b\\d+\\b"
. This Regex is good in the sense that it would exclude any numericalAlpha mix words like a4 bc3
.
The issue happens when the user will input Strings like
String s1 = "I have 2 345 bananas";
String s2 = "I have 2,345 bananas";
String s3 = "I have #2345 bananas";
String s4 = "I have 5654 6 bananas";
My program should output an empty string in the above cases as none are valid numbers in the input String.