0

I have the below string in arabic

دار لعادي ٢٠٠ موج

I want to get only the number so the output:

٢٠٠

the below will not work because to consider only english or latin:

try (BufferedReader reader = Files.newBufferedReader(p1, charset)) {
            String line = null;
            while ((line = reader.readLine()) != null) {
                 String str = line;
                str = str.replaceAll("[^\\d.]", "");

                   }

I tried to use this Character.isDigit(char ch) but I have String

Moudiz
  • 7,211
  • 22
  • 78
  • 156
  • try `str = str.replaceAll("[\u0660-\u0669]+", "")` – Al-Mothafar Jun 17 '21 at 12:06
  • `[^ .]` is correct, but `\\d` doesn't match arabic numbers. See the duplicate link on how to do that. – Tom Jun 17 '21 at 12:08
  • @Tom `str = str.replaceAll("[\u0660-\u0669]+", ""); ` the replace all is removing the number, what should I put instead ? – Moudiz Jun 17 '21 at 12:12
  • Note that the duplicate link explain how to check if arabic AND number characters. I want only number characters – Moudiz Jun 17 '21 at 12:14
  • You've already managed to write a regex to replace _everything else_ and I told you that this part `[^ .]`, which does exactly that, is correct ... so why have you removed it? – Tom Jun 17 '21 at 12:44
  • *"Note that the duplicate link explain how to check if arabic AND number characters."* ... the top/accepted answer explicitly states which part to use for characters and which part for numbers. So you want so say, that you can't ignore the part regarding characters and just use the part regarding numbers? – Tom Jun 17 '21 at 12:46

0 Answers0