I want help with regular expressions to solve the following problem:
I have a string such as \"1£23$456$£$\"
when I split on it I want the output in my strin
Use the more powerful Matcher functionality instead of String.split. The below code should work, but has not been optimized:
Pattern pattern = Pattern.compile("\\d*(\\$|£)");
String input = "1£23$456$£$";
Matcher matcher = pattern.matcher(input);
List output = new ArrayList<>();
while (matcher.find()) {
output.add(matcher.group());
}
Printing out output.toString() generates:
[1£, 23$, 456$, £, $]
Updated requirements:
+, -, *, and /Use the regular expression: \\d*\\s*[-\\+\\*/\\$£]
That pattern, with this given input:
1£23$456$£$7+89-1011*121314/1 £23 $456 $ £ $7 +89 -1011 * 121314 /
Will generate this output:
[1£, 23$, 456$, £, $, 7+, 89-, 1011*, 121314/, 1 £, 23 $, 456 $, £, $, 7 +, 89 -, 1011 *, 121314 /]