Answer the question
In order to leave comments, you need to log in
How to get the desired regexp result by pattern from text, not bool?
Given text:
`From:` <@317989885321674753>
`To:` <@163995016027439106>
`Reason:` <@!163995016027439106> ....
You need to use regular expressions to get from it only the first one similar to "317989885321674753" it's just some ID is always the same length (18) and always digits.
Thank you!
Answer the question
In order to leave comments, you need to log in
Like this:
https://play.golang.org/p/cPnYojRRPP3
package main
import (
"fmt"
"regexp"
)
func main() {
text := "`От:` <@317989885321674753>\n`На:` <@163995016027439106>\n`Причина:` <@!163995016027439106>"
re := regexp.MustCompile(`\<\@\!?(\d{18})\>`)
matches := re.FindAllStringSubmatch(text, -1)
for _, match := range matches {
if len(match) > 1 {
fmt.Println(match[1])
}
}
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question