LoginSignup
0
0

More than 5 years have passed since last update.

Golangにおいて正規表現で記号が含まれているのを省く

Last updated at Posted at 2019-03-06

アルファベット+数字+アンダーバーのみが含まれているかどうかを確認したいと思った。
なかなかコードが見つからず困る。

ぐぐりまくったら、StackOverFlowから下記の方法を発見した。

regexp.MustCompile("正規表現").MatchString("文字列") //boolで返却
package main

import "log"
import "regexp"

var ValueCheck = regexp.MustCompile("^[0-9a-zA-Z_]+$").MatchString

func main() {
        var table = "Adas;lmf___/.d,"
        if !ValueCheck(table) {
        log.Panicln("table name must be alphanumeric + _ .")
    }
}

Ref

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0