package main
import (
"regexp"
"fmt"
)
func main() {
var re = regexp.MustCompile(`(?m)(?:\b\w++::\w++\s*+\(|\G(?<!^))\s*+(\w++)\s*+(?:\[[^]]*+]\s*+)?,`)
var str = `Not even sure how to attack this Regex Need (Multiline text with extraction of library names)
Sample Text
box::use(
DBI[dbListTables, dbExecute],
Yessir[this_one, that one,
and_this_one],
Maybesir[
func_one,
func_two,
],
Nosir,
database = logic/database,
log = logic/log,
options = logic/options,
utilities = logic/utilities,
)
I would like to have a regexp which matches the following from the above text:
DBI, Yessir, Maybesir, Nosir
Is there an easy way to approach this? I have been trying to use the regexp101 website to help me out here, but this one is sufficiently complex that I am a bit out of my depth. My current line is the following:
box::use\(\n(?:[\s]*([A-Za-z0-9]*)(?:[A-Za-z0-9\[\]_\ ,]*\n))
But, this is of course not getting it. I am not sure how to handle getting the multiple (unknown how many there really would be) libraries inside the box::use function.
It might be easier to extract the text from inside the use::box function first and then regexp that?
Edit: Forgot to add that I am using Python3`
for i, match := range re.FindAllString(str, -1) {
fmt.Println(match, "found at index", i)
}
}
Please keep in mind that these code samples are automatically generated and are not guaranteed to work. If you find any syntax errors, feel free to submit a bug report. For a full regex reference for Golang, please visit: https://golang.org/pkg/regexp/