How to extract numbers from a string?

前端 未结 10 2107
青春惊慌失措
青春惊慌失措 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:57

    You can also use sed:

    echo "toto.titi.12.tata.2.abc.def" | sed 's/[0-9]*//g'
    

    Here, sed replaces

    • any digits (class [0-9])
    • repeated any number of times (*)
    • with nothing (nothing between the second and third /),
    • and g stands for globally.

    Output will be:

    toto.titi..tata..abc.def
    

提交回复
热议问题