K
K
kr_ilya2020-10-24 18:07:40
go
kr_ilya, 2020-10-24 18:07:40

How to get individual elements of a string with a regular expression?

I get a regular expression from html and get a set of lines like
/reports/schedule/Group/14779_1_26102020_08112020.pdf

groupRegexp := regexp.MustCompile("/reports/schedule/Group/[0-9]{4,}_[1|2]_[0-9]{8}_[0-9]{8}.pdf")

doc := GetHtml(config.C.GroupPage) // Получение html кода страницы

datesGroup := groupRegexp.FindAllString(doc, -1)

for _, val := range datesGroup {
  fmt.Println(val) // вывод найденных элементов
}


How can I get from a string like this, the values ​​corresponding to 14779 , 1 , 26102020 , 08112020 in the above string. It is desirable to assign a separate variable for each value.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
dollar, 2020-10-24
@kr_ilya

\/(\d{5})_(\d)_(\d{8})_(\d{8})\.
https://regex101.com/r/8CBTnX/1

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question