Last active
August 29, 2015 13:55
-
-
Save knu2xs/8786365 to your computer and use it in GitHub Desktop.
Replaces or drops invalid characters from names according to rules for naming feature classes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fix_invalid_characters(self, string): | |
""" | |
Drops invalid characters from names according to rules for naming feature classes, notably must | |
start with a letter and remaining characters must be numbers, letters or underscores. | |
""" | |
# drop invalid characters at beginning of string | |
string = re.sub(r'^[^a-zA-Z]+', '', string) | |
# find any invalid characters in remainder of string and replace with underscores | |
return re.sub(r'[^a-z0-9A-Z_]', '_', string) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment