package com.mortals.xhx.common.pdu;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.util.ReUtil;
import cn.hutool.core.util.StrUtil;
import lombok.Data;
import org.springframework.util.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.stream.Collectors;

/**
 * @author: zxfei
 * @date: 2021/10/25 11:17
 * @description:
 **/
@Data
public class NodeEntity {

    private String id;

    private String parentId;

    private String tagName;

    private String nodeType;

    private String content;

    private Integer num;


    public static void main(String[] args) {


        String testStr="${i_1_谁知道}1231 ${i_1_那} 1 ${i_1_111那}";

        String text="";


        String regEx = "\\$\\{(.*)\\}";
        Pattern pattern = Pattern.compile(regEx);
        Matcher matcher = pattern.matcher(testStr);

//        if(matcher.find()){
//
//            System.out.println(matcher.group());
//        }

        //matcher.group();


        List<String> allGroups = ReUtil.getAllGroups(pattern, testStr);
        if (!ObjectUtils.isEmpty(allGroups)) {
            text = CollUtil.join(allGroups, ";");
        }

        String collect = Arrays.asList(testStr.split("\\$")).stream().map(String::trim)
                .map(item -> StrUtil.subBetween(item, "{", "}"))
                .filter(f->f!=null)
                .map(item->"${"+item+"}")
                .collect(Collectors.joining(";"));

        //System.out.println(JSON.toJSONString(split));

        //List<String> split = StrSpliter.split(testStr,"\\$", true,true);

       // String collect = StrUtil.split(testStr, "\\$", -1, true, true).stream().map(item -> StrUtil.subBetween(item, "{", "}")).collect(Collectors.joining(";"));


        System.out.println(collect);
    }
}
