I asked a question here: Regex: Differentiate boundary match ^ and Negation about a regex to be applied in method replaceAll(), to get a String with only digits and the minus sign (-) to allow negative numbers as well. I run the follow and it works fine in my java interpreter:
String onlyDigits = currencyStringValue.replaceAll("[\\D-]","").replaceAll("(?<!^)-","");
If I input: --25#54d51 -> Returns: -255451
25#54-d51 -> Returns: 255151
-25#54d51 -> Returns: -255451
dz-255451 -> Returns: -255451
But I'm trying the same thing in Android Studio, and only returns digits, debugging the app, I notice the onlyDigits get only numbers 0-9, ignoring the minus sign (-) in beginning...
What is it wrong and if there is a problem in code or solution, how can I solve this?
Thanks!
replaceAll("[\\D]","")removes any non-digit character including-. What are you trying to do here?String onlyDigits = currencyStringValue.replaceAll("[^-\\d]","").replaceAll("(?<!^)-","");.