Golang regexp/syntax.IsWordChar() function example
package regexp/syntax
Golang regexp.syntax.IsWordChar() function usage example.
NOTE : These assertions are ASCII-only: the word characters are [A-Za-z0-9_].
package main
import (
"fmt"
"regexp/syntax"
)
func main() {
word1 := []rune("alpha")
word2 := []rune("吃")
word3 := []rune("1234")
word4 := []rune(" $#$^@#$ ")
ok := syntax.IsWordChar(word1[0])
fmt.Printf("%v is a word ? : %v \n", string(word1), ok)
ok = syntax.IsWordChar(word2[0])
fmt.Printf("%v is a word ? : %v \n", string(word2), ok)
ok = syntax.IsWordChar(word3[0])
fmt.Printf("%v is a word ? : %v \n", string(word3), ok)
ok = syntax.IsWordChar(word4[0])
fmt.Printf("%v is a word ? : %v \n", string(word4), ok)
}
Output :
alpha is a word ? : true
吃 is a word ? : false
1234 is a word ? : true
$#$^@#$ is a word ? : false
Reference :
Advertisement
Something interesting
Tutorials
+12.9k Golang : Add ASCII art to command line application launching process
+13.1k Golang : Get terminal width and height example
+8k Golang : Gomobile init produce "iphoneos" cannot be located error
+36.2k Golang : Smarter Error Handling with strings.Contains()
+5.9k Golang : List all packages and search for certain package
+9.4k Golang : Generate random Chinese, Japanese, Korean and other runes
+10.5k Golang : cannot assign type int to value (type uint8) in range error
+5.6k Golang : If else example and common mistake
+55.5k Golang : Unmarshal JSON from http response
+9.6k Golang : Extract or copy items from map based on value
+5.7k Swift : Get substring with rangeOfString() function example