问题
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