K="Google Chrome 75.0.3770.100"
echo ${K//[a-zA-Z]/}
Output
75.0.3770.100
Expected Output
75
Need to remove all the characters starting from a specific index character; say .
You can use extglob
to get this done in single step:
shopt -s extglob
K="Google Chrome 75.0.3770.100"
echo "${K//@([a-zA-Z ]|.*)/}"
75
Expression Details:
@(...)
: Match one of the expressions inside (...)
separated by |
[a-zA-Z ]
: Match [a-zA-Z]
letters or space |
: or .*
: Any string starting from a dot
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.