Break string into columns using Regular Expression

陌路散爱 提交于 2019-12-13 23:53:12

问题


I am new in regex, i want to break the give string into 6 parts using regular expression. I am using the Pentaho data integration tool (ETL tool)

Given string: 1x 3.5 mL SST. 1x 4.0 mL gray cap cryovial.

Note: There are many more string with same format

I want output as:

Thanks in advance !!


回答1:


The single string datum you've given looks like it should match the regex pattern:

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

You can use it with Regex Evaluation step:




回答2:


Use split function and regex \. | 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>


来源:https://stackoverflow.com/questions/49130808/break-string-into-columns-using-regular-expression

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!