FFMResolverTest.java 2.5 KB
import com.tianbo.util.IO.FileTool;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;


public class FFMResolverTest {

    public static void main(String[] args) {

        File ffmfile = new File("/Users/mrz/Documents/java项目/新郑机场/util/ffm1.txt");
        String qd = "HKGFDXH HKGFGXH HKGFMXH TSNCTXH HKGORXH HKGOPXH HKGFRUD ";
        List<String> list = new ArrayList<>();
        try {
            String ffmStr =  FileTool.readfile(ffmfile);
//            (\d{1,})/([A-Z0-9]+)/([A-Z0-9]+)/([A-Z]{3})(/[A-Z0-9]+)?[\s\S]+TSN[\s\S]+ULD/([A-Z0-9]{10})[\s\S]+(\d{3}-\d{8}[A-Z]{6})/(S|P|T|D|M)(\d+)K(\d+|[1-9]\d*\.\d*|0\.\d*[1-9]\d*)MC(\d+|[1-9]\d*\.\d*|0\.\d*[1-9]\d*)T(\d+)/(.*)
            // 按指定模式在字符串查找
            String ffm_pattern = "(\\d{1,})/([A-Z0-9]+)/([A-Z0-9]+)/([A-Z]{3})(/[A-Z0-9]+)?[\\s\\S]+TSN[\\s\\S]+ULD/([A-Z0-9]{10})[\\s\\S]+(\\d{3}-\\d{8}[A-Z]{6})/(S|P|T|D|M)(\\d+)K(\\d+|[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)MC(\\d+|[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)T(\\d+)/(.*)";
            //先找出航班信息
            String pattern1_flght = "ULD/([A-Z0-9]{10})[\\s\\S]+(\\d{3}-\\d{8}[A-Z]{6})/(S|P|T|D|M)(\\d+)K(\\d+|[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)MC(\\d+|[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)T(\\d+)/(.*)";
            //再找出航班下的所有目的地的货
            String pattern_destination = "([\\t\\r\\n]" +
                    "[A-Z]{3}[\\s*]?[\\t\\r\\n])" +
                    "(ULD/[A-Z0-9]{10}.*(\\d{3}-\\d{8}[A-Z]{6})/(S|P|T|D|M)(\\d+)K(\\d+|[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)MC(\\d+|[1-9]\\d*\\.\\d*|0\\.\\d*[1-9]\\d*)(T\\d+)?/([\\u4E00-\\u9FA5]+|.*))[\\t\\r\\n]([A-Z]{3})[\\s*]?[\\t\\r\\n]";
            //取航班所有货物内容列表,取消Pattern.DOTALL,获得所有航站信息
            String pattern_manifest = "^[A-Z]{3}/?[\\s*]?$";
            //取运单板箱
            String pattern_awb = "";
            // 创建 Pattern 对象
            Pattern pattern = Pattern.compile(pattern_manifest,Pattern.MULTILINE|Pattern.DOTALL);

            // 现在创建 matcher 对象
            Matcher matcher = pattern.matcher(ffmStr);
            while (matcher.find()) {
                list.add(matcher.group());
                System.out.println("适配结果: " + matcher.group() );
            }
            System.out.println(list);
        }catch (Exception e){
            e.printStackTrace();
        }

    }
}