I want to check if arguments passed in stdin to see if they conform to a valid java package name. The regex I have is not working properly. With the following code passing in com.example.package I receive the error message. I'm not sure what is wrong with my regex?
regex="/^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/i"
17 if ! [[ $1 =~ $regex ]]; then
18 >&2 echo "ERROR: invalid package name arg 1: $1"
19 exit 2
20 fi