How can I check if a given string contains non numeric characters, examples :
x11z returns > 0
x$1 also returns > 0
1111~ also returns > 0
By character I mean everything not between 0-9
. I saw similar threads but non of them talks about "non 0-9" except they show if its a-z
or A-Z
.
Just use a negated character class:
grep [^0-9]
This will match any non-numeric character, and not strings composed of only digits.
Just by using bash
pattern matching:
[[ "$MY_VAR" =~ ^[^0-9]+$ ]] && echo "no digit in $MY_VAR"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With