How to extract numbers from a string?

前端 未结 10 2104
青春惊慌失措
青春惊慌失措 2020-12-10 04:20

I have string contains a path

string=\"toto.titi.12.tata.2.abc.def\"

I want to extract only the numbers from this string.

To extrac

10条回答
  •  生来不讨喜
    2020-12-10 04:55

    This would be easier to answer if you provided exactly the output you're looking to get. If you mean you want to get just the digits out of the string, and remove everything else, you can do this:

    d@AirBox:~$ string="toto.titi.12.tata.2.abc.def"
    d@AirBox:~$ echo "${string//[a-z,.]/}"
    122
    

    If you clarify a bit I may be able to help more.

提交回复
热议问题