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

问题描述 投票:-2回答:2

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

给定字符串:1x 3.5 mL SST。 1x 4.0 mL灰帽冷冻。

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

我希望输出为:enter image description here

提前致谢 !!

javascript regex pentaho pentaho-spoon pentaho-data-integration
2个回答
1
投票

您给出的单字符串数据看起来应该与正则表达式模式匹配:

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

您可以将它与Regex Evaluation步骤一起使用:

Regex Evaluation


1
投票

使用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>
© www.soinside.com 2019 - 2024. All rights reserved.