+ 3

How to print only The Numbers from a alphanumeric String?

Eg. Input sdg45mkf567kdd3j(Take Input As A String) Output 45 567 3

5th Nov 2017, 10:16 AM
Shubham Pratap Singh
Shubham Pratap Singh - avatar
8 Respuestas
5th Nov 2017, 10:45 AM
Ipang
+ 5
Use regular expressions... As methods names depends on wich language implementation, example in Javascript: var inp = 'sdg45mkf567kdd3j'; var out = inp.replace(/[^\d]+/g,' '); console.log('>'+out+'<'); ... or in two times, to strip eventuals boundings spaces: var out = inp.replace(/^[^\d]+|[^\d]+$/g,'').replace(/[^\d]+/g,' '); console.log('>'+out+'<');
5th Nov 2017, 10:38 AM
visph
visph - avatar
+ 3
If I know how, I would recommend it like @visph example, using RegEx, less code to write, and no need to reinvent the wheel :)
5th Nov 2017, 10:53 AM
Ipang
+ 3
@Ipang: so, I suppose there's no built-in regex parser in C++? But I guess there's some in Java, doesn't it?
5th Nov 2017, 11:08 AM
visph
visph - avatar
+ 3
@visph, I really don't know how to use regex in C++, as a matter of fact I'm still having difficulties understanding the meaning/usage of regex string filter, maybe I should make this a homework :)
5th Nov 2017, 12:58 PM
Ipang
+ 2
No, I can't: I never have used regular expression with those languages... I can do it in Python if you want ^^
5th Nov 2017, 10:44 AM
visph
visph - avatar
+ 1
@visph Can You Send Me The Codes In C,c++ or Java?? I am not familiar with JavaScript.. So plzz
5th Nov 2017, 10:43 AM
Shubham Pratap Singh
Shubham Pratap Singh - avatar
0
yeah!! Thank You Very Much 😊
5th Nov 2017, 10:47 AM
Shubham Pratap Singh
Shubham Pratap Singh - avatar