There are several cases where we find alphanumeric characters like Vehicle Name plates (e.g. UP 16 BL 4405), Address Number plates (e.g. Aditya Agnihotri, Flat no, G- 102, Noida) and so on.
Sometimes we only need the digits from such alphanumeric strings. Now if we see the Address which is – “Aditya Agnihotri, Flat no, G- 102, Noida”, it contains alphabets, comma, hyphen and so on. But form this Address we only need to extract digits which i.e. 102. Now to have such logic we need to write few lines of code in every language.
But here i am providing you single line solution in JAVA.
String Address = "Aditya Agnihotri, Flat no, G- 102, Noida" String Address_Digits = Address.replaceAll("[-+.^:,]",""); System.out.println("Flat number is - "+Address_Digits);
O/P of above program – 102
Happy Coding 🙂