bash string check
bash string check
(OP)
Hello,
why test returns "clean" what is marked in red in belongs strings comparison?
CODE -->
# d=274y82heE # [[ $d =~ [^[:alnum:]] ]] && echo "not clean $d" || echo "clean $d" clean 274y82heE # d=274y82he^E # [[ $d =~ [^[:alnum:]] ]] && echo "not clean $d" || echo "clean $d" not clean 274y82he^E # d=/one/ssfdsf/274y82he^E/end/end # [[ $d =~ /one/ssfdsf/[^[:alnum:]]/end/end ]] && echo "not clean $d" || echo "clean $d" clean /one/ssfdsf/274y82he^E/end/end # [[ $d =~ /one/ssfdsf/[[:alnum:]]/end/end ]] && echo "not clean $d" || echo "clean $d" clean /one/ssfdsf/274y82he^E/end/end # [[ $d =~ ^/one/ssfdsf/[[:alnum:]]/end/end ]] && echo "not clean $d" || echo "clean $d" clean /one/ssfdsf/274y82he^E/end/end # [[ $d =~ ^/one/ssfdsf/[[:alnum:]]/end/end$ ]] && echo "not clean $d" || echo "clean $d" clean /one/ssfdsf/274y82he^E/end/end
RE: bash string check
- [[:alnum:]] - one alphanumeric character
- [^[:alnum:]] - one non-alphanumeric character
In that place you have 8 alphanumeric character, then 1 non-alphanumeric character, then 1 alphanumeric character.Not sure what is your goal, but try something like this :
CODE --> Bash
Feherke.
feherke.ga
RE: bash string check
ok. but it doesn't return clean when I expect it clean:
CODE -->
the goal is to check if there is "alnum" between ^/one/ssfdsf/ and /end/end$
RE: bash string check
Your current regular expression says :
- starts with "/one/ssfdsf/"
- then 1 alphanumeric character
- then any number of any character
- ends with "/end/end"
As your current string looks exactly like that, so the 1st echo gets executed, saying "not clean".Your current regular expression says in that place has to be 1 alnum followed by anything or nothing.
I think you want this, so in that place to have 1 or more alphanumeric characters :
CODE --> Bash
Feherke.
feherke.ga
RE: bash string check
indeed, I was pretty sure I had tested [[:alnum:]]+ in one of my first tries... I must had done some mistake