如何在符号前捕获字符串

时间:2017-09-25 01:45:15

标签: regex perl

早上好, 我想在冒号前捕获字符串: 然后比较冒号后的字符串 并删除与冒号前的值相等的值。

例如:

aaa:aaa-bbb-ccc

输出:

aaa others:bbb,ccc

我的代码

$string = "aaa:aaa-bbb-ccc";
$first =~ /(:.*\)/; //get aaa before the colon
$others =$string=~ s/$first//; remove the same values after colon
你能帮我吗?谢谢..

1 个答案:

答案 0 :(得分:0)

这有效:

func jsonDecoding() {
    let jsonUrlString = "https://kitsu.io/api/edge/anime"

    guard let url = URL(string: jsonUrlString) else {return} //
    URLSession.shared.dataTask(with: url) { (data, response, err) in
        guard let data = data else {return}
        do {
            let animeJsonStuff =  try JSONDecoder().decode(AnimeJsonStuff.self, from: data)
            for anime in animeJsonStuff.data {
                print(anime.id)
                print(anime.type)
                print(anime.links?.selfStr)
                print(anime.attributes?.createdAt)
                for (key, value) in anime.relationships! {
                    print(key)
                    print(value.links?.selfStr)
                    print(value.links?.related)
                }
            }
        } catch let jsonErr {
            print("Error serializing json", jsonErr)
        }
    }.resume()
}