V
V
Vadim Rublev2021-09-07 00:47:44
go
Vadim Rublev, 2021-09-07 00:47:44

How to write a regular expression with a variable inside?

How to correctly write a regular expression (specified in Compile() )?

myFile := значение_из_конфига
text := , err = ioutil.ReadFile("testFile.txt")
myRegexp, err = regexp.Compile(`начинается с " далее любые_символы_или_их_отсутствие далее myFile далее "`)
new_string := `"` + "prefix_" + myFile + `"`
strings.ReplaceAll(string(text), myRegexp, new_string)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
Fedor Lapshin, 2021-09-24
@FedLapshin06

Based on the context provided, I can assume what fmt.Sprintfwould be the easiest option in this situation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question