package com.yutou.nas.utils;

import java.util.Objects;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class PatternTools {
    private static String exec(String regex,String input){
        Pattern pattern=Pattern.compile(regex);
        Matcher matcher = pattern.matcher(input);
        if(matcher.find()){
            return matcher.group();
        }
        return null;
    }
    public static String getMagnetHash(String magnetLink){
        System.out.println("magnetLink = " + magnetLink);
        String ret=exec(".(?<=btih:).*(?=&dn)", magnetLink);
        if(ret==null){
            ret=exec(".(?<=btih:).*(?=&amp;dn)",magnetLink);
        }
        return Objects.requireNonNull(ret).substring(1);
    }
}
