habraview/habr/util.v
2024-11-03 14:32:04 +03:00

13 lines
238 B
V

module habr
import regex
pub fn get_id_from_url(url string) ?string {
mut re := regex.regex_opt(r'/\d+/?$') or { return none }
begin, end := re.find(url)
if begin > 0 && end > 0 {
return url[begin..end].trim('/')
}
return none
}