0

Подскажите: как в го вытащить цифры из строки?

1 ответ 1

1

Можно сделать регулярное выражение:

package main

import "fmt"
import "regexp"

func main() {
    str := "Hello, today is January 11. I am 28 now. Date of birth 11.01.1990."

    fmt.Println("Test string", str)

    re := regexp.MustCompile("[0-9]+")
    fmt.Println(re.FindAllString(str, -1))
}

Запустить код можно здесь: https://play.golang.org/p/4FayPuOwBSx

1

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Всё ещё ищете ответ? Посмотрите другие вопросы с метками или задайте свой вопрос.