代码之家  ›  专栏  ›  技术社区  ›  DHARMINDER

使用正则表达式将字符串拆分为列

  •  -2
  • DHARMINDER  · 技术社区  · 7 年前

    我是regex新手,我想使用正则表达式将给定字符串分成6部分。我正在使用Pentaho数据集成工具(ETL工具)

    给定字符串: 1x 3.5 mL不锈钢。1x 4.0 mL灰盖冷冻瓶。

    注意:有更多相同格式的字符串

    我希望输出为: enter image description here

    提前谢谢!!

    2 回复  |  直到 7 年前
        1
  •  1
  •   Nae    7 年前

    这个 仅有一个的 您给出的字符串数据看起来应该与regex模式匹配:

    (\d*)x\s(\d*\.\d*)\smL\s(.*)\.\s(\d*)x\s(\d*\.\d*)\smL\s(.*)\.
    

    您可以将其用于 Regex Evaluation 步骤:

    Regex Evaluation

        2
  •  1
  •   Srdjan M.    7 年前

    使用 split 函数和正则表达式 \. | mL |x

    var text = '1x 3.5 mL SST. 1x 4.0 mL gray cap cryovial'
    arr = text.split(/\. | mL |x /g)
    
    var tb = document.getElementById("table")
    //creat row
    var tr = document.createElement("tr")
    
    for (s of arr) {
      // create cell
      var td = document.createElement("td")
      var txt = document.createTextNode(s);
      td.appendChild(txt)
      tr.appendChild(td)
    }
    
    tb.appendChild(tr);
    <table id='table' border="1">
      <tr>
        <th>Par_Count</th>
        <th>Par_Qty</th> 
        <th>Par_Tube</th>
        <th>Child_Count</th>
        <th>Child_Qty</th>
        <th>Child_Tube</th>
      </tr>
    </table>