正则匹配

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>
{"Content":"欧尚超市","Len":"4","X":"10","Y":"74"}
{"Content":"数量","Len":"4","X":"10","Y":"74"}
{"Content":"商品示例一  1.00  10.00","Len":"22","X":"10","Y":"242"}
{"Content":"商品18  1.00  1.00","Len":"19","X":"10","Y":"458"}
{"Content":"商品19  1.00  1.00","Len":"19","X":"10","Y":"482"}
{"Content":"商品20  1.00  1.00","Len":"19","X":"10","Y":"506"}
{"Content":"*不征税测试3* 3.00 2.00 6.00","Len":"32","X":"10","Y":"98"}
{"Content":"欧尚超市","Len":"4","X":"10","Y":"74"}

<body>
    <script>
        // var str = '{"Content":"欧尚超市","Len":"4","X":"10","Y":"74"}{"Content":"数量","Len":"4","X":"10","Y":"74"}{"Content":"商品示例一  1.00  10.00","Len":"22","X":"10","Y":"242"}{"Content":"商品fdsafsa  1.00  1.00","Len":"19","X":"10","Y":"458"}{"Content":"商1品19 , 1.00 , 1.00","Len":"19","X":"10","Y":"482"}{"Content":"商品20  1.00  1.00","Len":"19","X":"10","Y":"506"}{"Content":"*不征税测试3* 3.00 2.00 6.00","Len":"32","X":"10","Y":"98"}{"Content":"欧尚超市","Len":"4","X":"10","Y":"74"}';
        var str = '{"Content":"苹果                 11.00       1.00       11.00","Len":"38","X":"0","Y":"104.8177"}{"Content":"*不征税测试3* 2.00 15.00 30.00","Len":"32","X":"10","Y":"98"}';
        // var regexData = str.match(/\{"Content":".+(\s+\d+\.{1}\d{2})*","Len":"\d+","X":"\d+","Y":"\d+"\}/g);
        var regexData = str.match(/\{"Content":"(\**[^\x00-\xff]*\w*)+((\s|,)+\d+(\.{1}\d+)*)+","Len":"\d+(\.{1}\d+)*","X":"\d+(\.{1}\d+)*","Y":"\d+(\.{1}\d+)*"\}/g);
        console.log(regexData);
        var arr1 = [];
        for(let i = 0; i < regexData.length; i++){
            arr1.push(JSON.parse(regexData[i]))
        }
        var arr2 = [];
        for(let i = 0; i < arr1.length; i++){
            var requireData = arr1[i].Content.replace(/(,|\s)+/g,',').split(',');
            console.log(requireData);
            // arr2
        }
        // console.log(arr);
    </script>
</body>

</html>

 

posted @ 2019-08-12 16:44  LaLaLa_heng  阅读(116)  评论(0编辑  收藏  举报