使用正则表达式将字符串分成列
Break string into columns using Regular Expression
我是正则表达式的新手,我想使用正则表达式将给定的字符串分成 6 个部分。我使用的是Pentaho数据集成工具(ETL工具)
给定字符串: 1x 3.5 mL SST。 1x 4.0 mL 灰盖冷冻管。
注意:相同格式的字符串还有很多
我希望输出为:
提前致谢!!
使用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>
您提供的 单个 字符串数据看起来应该与正则表达式模式匹配:
(\d*)x\s(\d*\.\d*)\smL\s(.*)\.\s(\d*)x\s(\d*\.\d*)\smL\s(.*)\.
您可以通过 Regex Evaluation
步骤使用它:
我是正则表达式的新手,我想使用正则表达式将给定的字符串分成 6 个部分。我使用的是Pentaho数据集成工具(ETL工具)
给定字符串: 1x 3.5 mL SST。 1x 4.0 mL 灰盖冷冻管。
注意:相同格式的字符串还有很多
我希望输出为:
提前致谢!!
使用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>
您提供的 单个 字符串数据看起来应该与正则表达式模式匹配:
(\d*)x\s(\d*\.\d*)\smL\s(.*)\.\s(\d*)x\s(\d*\.\d*)\smL\s(.*)\.
您可以通过 Regex Evaluation
步骤使用它: