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
+15k Golang : Execute terminal command to remote machine example
+5.1k Golang : Convert Chinese UTF8 characters to Pin Yin
+10.3k Golang : Display a text file line by line with line number example
+33.8k Golang : Save image to PNG, JPEG or GIF format.
+28k Golang : missing Git command
+11.7k Python : Convert IPv6 address to decimal and back to IPv6
+15.4k Golang : Set up source IP address before making HTTP request
+7k Golang : Tell color name with OpenCV example
+7.8k Golang : Write multiple lines or divide string into multiple lines
+12.9k Golang : concatenate(combine) strings
+25.8k Golang : Convert CSV data to JSON format and save to file