iml_api_utils/
lib.rs

1// Copyright (c) 2020 DDN. All rights reserved.
2// Use of this source code is governed by a MIT-style
3// license that can be found in the LICENSE file.
4
5use lazy_static::lazy_static;
6use regex::Regex;
7
8/// Given a resource_uri, attempts to parse the id from it
9pub fn extract_id(s: &str) -> Option<&str> {
10    lazy_static! {
11        static ref RE: Regex = Regex::new(r"^/?api/[^/]+/(\d+)/?$").unwrap();
12    }
13    let x = RE.captures(s)?;
14
15    x.get(1).map(|x| x.as_str())
16}