Using

```
regex='^[]0-9a-zA-Z,!^`@{}=().;/~_|[-]*$'

```

in below script file I am checking if a given string has any invalid characters or not.

```
str="$1"

regex='^[]0-9a-zA-Z,!^`@{}=().;/~_|[-]+$'

if [[ $str =~ $regex ]]
then
  echo "matches"
  echo "Match: ${BASH_REMATCH[0]}"
else
  echo "doesn't match"
fi

```

As there is an option to get matched string using BASH\_REMATCH, is there any option to get which invalid character was present in the string if string does not match?