I want to write a script that matches everything that has either a character from the alphabet, a number, and an underscore. Possible valid strings:
asd_asd
Asd_asd
asd_123
123_asd
123_aSD
and so on. What I tried so far is:
if [[ "$LINE" =~ [a-zA-Z0-9_] ]]
But this will match any character that contains also any of these: !@#$%^&*()_+}{|?><`!, and other weird symbols.
I thought about putting the special characters in a list, and ignore a string if it contains one of the characters in the list, but I am afraid I can skip one character.
What is it better to do in this case?
[a-zA-Z0-9_], is that correct? What about the empty (zero-length) string? BTW, your current pattern will match strings that contain at least one[a-zA-Z0-9_](that is, "@@@@a@@@@" would match, but "@@@@" wouldn't).