An identifier is a non-empty string made up of letters, digits, and underscores, where the first character
is not a digit. Keywords are not identifiers.
The regex defined in the library currently expects an identifier to begin and end with a letter.
^[A-Za-z]([A-Za-z0-9_]*[A-Za-z])?$
I switched the regex usage to fit the description of an identifier defined in Go. That way, v1 can be identified as a valid package name.
I wonder if it is better to switch to using the IsIdentifier method from go/token instead of relying on a regex, let me know if this works so I can update the pull request to make use of this method instead of the regex.
It seems the regex for identifying valid Go identifiers is wrong.
According to the Go source code,
The regex defined in the library currently expects an identifier to begin and end with a letter.
^[A-Za-z]([A-Za-z0-9_]*[A-Za-z])?$
I switched the regex usage to fit the description of an identifier defined in Go. That way,
v1
can be identified as a valid package name.I wonder if it is better to switch to using the
IsIdentifier
method fromgo/token
instead of relying on a regex, let me know if this works so I can update the pull request to make use of this method instead of the regex.