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

时间:2018-03-06 12:24:55

标签: javascript regex pentaho pentaho-spoon pentaho-data-integration

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

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

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

我希望输出为: enter image description here

提前致谢!!

2 个答案:

答案 0 :(得分: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>
&#13;
&#13;
&#13;

答案 1 :(得分:1)

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

if

您可以将其与0步骤一起使用:

Regex Evaluation