def valid_name(name):
r"""Determine whether or not the given string is a valid
alphanumeric string.
Parameters
----------
name : str
An alphanumeric identifier.
Returns
-------
result : bool
``True`` if the name is valid, else ``False``.
Examples
--------
>>> valid_name('alpha') # True
>>> valid_name('!alpha') # False
"""
identifier = re.compile(r"^[^\d\W]\w*\Z", re.UNICODE)
result = re.match(identifier, name)
return result is not None
评论列表
文章目录