问题描述
我正在尝试在golang正则表达式中的以下sql语句的括号中获取所有内容.
I am trying to get everything within the outside brackets of the following sql statement in golang regular expressions.
Categories
(// = outside bracket
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)//=outside bracket
我将如何使用正则表达式仅识别外括号并返回外括号之间的所有内容?
how would I use regex to only identify the outer brackets and return everything in between the outside brackets?
推荐答案
()
()
`(?s)\((.*)\)`
详细信息:
(?s). \(((.*) \))
(?s).\(((.*)\))
package main
import (
"fmt"
"regexp"
)
func main() {
s := `Categories
(// = outside bracket
PersonID int,
LastName varchar(255),
FirstName varchar(255),
Address varchar(255),
City varchar(255)
)//=outside bracket`
re := regexp.MustCompile(`(?s)\((.*)\)`)
m := re.FindAllStringSubmatch(s,-1)
fmt.Printf("Capture value: %s", m[0][1])
}
这篇关于如何使用正则表达式将所有内容放在golang的括号内的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!