package main
import (
"fmt"
"log"
"regexp"
)
func main() {
example := "#GoLa啊啊|ngCode!$!"
result := removeNonEng(example)
fmt.Printf("A string of %s becomes %s \n", example, result)
}
func removeNonEng(input string) string {
reg, err := regexp.Compile("[^a-zA-Z0-9]+")
if err != nil {
log.Fatal(err)
}
processedString := reg.ReplaceAllString(input, "")
return processedString
}
PHP 验证字符串中的非英语字符
/**
* A function used to validate non-english characters in a string using regex
*/
function validate_non_english_characters($string) {
$string = strtolower($string);
if (!preg_match('/^[a-z0-9]{3,15}$/', $string)) {
// do something
}
}