Quick actions

cmd+k|ctrl+k

Navigation

Languages

num+pf

Snippet info

Language

JavaScript

Visibility

public

Author

pheker

Created

2018-01-29T03:11:17Z

Updated

2018-01-29T05:41:55Z

console.log("Hello World!");


/**
 * 识别:
 * 数字或小数+[MnPpUuμNn][Ff]|μ 这样模式
 * 紧挨着这串字符前及后挨着的不能是中文及字母,
 * 数字小于10000
 */
let reg = /(\d{1,4}(?:\.\d+)?|10000)([mnpuμn]f|μ])/ig;
let non_letter_ch = /[^a-zA-Z\\u4e00-\\u9fa5±]/;

let strs =[
    "瓷片电容_贴片_1.5pF_±0.25pF_0402_50V_COG_GJM1555C1H1R5CB01_村田_PBF",
    "多层片状陶瓷电容_贴片_1μF_±20%_0201_10V_X5R_PBF",
    "ESD多层变阻器_贴片_9V_3PF_0402_ESDA0402-09_HUAYING_PBF",
    "瓷片电容_贴片_1.2pF_±0.25pF_0402_50V_COG"];
let ret = strs.map(function(v){
    let arr = v.split("_").filter(function(w,i){
        // console.log(i,w)
        let m,mList = [];
        while((m = reg.exec(w)) ){
            // console.log(m.index,reg.lastIndex)
            //前后前后非中文
            (m.index === 0 || non_letter_ch.test(m[0][m.index-1]))
            && (reg.lastIndex == m[0].length || non_letter_ch.test(m[0][reg.lastIndex] ))
            && mList.push(m[0]);
        }
        if(mList.length){
            return mList;
        }
    });
    // console.log(arr);
    return arr;
});


console.log(ret);

INFO