我有一个长文本,这是一个多行,需要提取文本,如图所示。
它们必须以这样的方式提取:#34;它从第二个括号开始#34;文字内容可能有所不同
如图所示结束。
因此,基于文本的正则表达式并不实用。我如何仅通过括号的位置进行匹配。
突出显示的文字是预期的输出
示例文字:
(ti,ab(((Abbott near / 10(化验* OR测试* OR分析* OR 阵列))或(雅培p / 1点P / 1护理)或ARCHITECT或( CELL p / 0 DYN))OR((Alere near / 10(测定* OR测试* OR分析* OR 阵列))或(Alere NEAR / 5(分类P / 1系统))或INRatio或Afinion)或((Beckman * p / 1 Coulter接近/ 10(测定* OR测试* OR分析* OR 阵列))或((Beckman * p / 0 Coulter)接近/ 2 AU? ???)OR(UniCel * P / 1 DxC)OR(UniCel * p / 1 DxI)OR(Beckman * near / 5 Access)OR(Access * p / 1 Systeme)OR(CytoFLEX OR(cyto p / 0 flex) ))OR(UniCel * p / 1 DxH)OR((Coulter * p / 1 LH)OR Coulter LH))OR((Ortho p / 0 Clinical P / 1 Diagnostics)或VITROS OR(vitros p / 1系统*)或(VITROS * p / 1 ECiQ)或ORTHOTM OR(orthotm p / 1 VISION)或(ORTHO p / 1 AutoVue *))或((仪器p / 0实验室)或HemosIL或ACLTOP OR (ACL p / 0 ELITE)或(GEM * P / 1 Premier)或GEM OPL)或((辐射计接近/ 10(分析 OR测试* OR分析* OR 阵列))OR(AQT ?? p / 0 FLEX)或(ABL ?? p / 0 FLEX)或HemoCue *)OR((Nova p / 0 Bi) omedical)或StatStrip OR(STAT p / 0 PROFILE *)或((Nova p / 0 Biomedical)近/ 1 Prime)或STATPROFILE *)或(((西门子p / 0 Healthcare)接近/ 10(化验* OR测试* OR analy * OR array ))OR(ADVIA p / 0 Centaur)OR(Dimension p / 0 Vista)或RAPIDPOINT)))和(ud(> 20170101))(见附件)
(ab(((Abbott near / 10(化验* OR测试* OR分析* OR 阵列))或(雅培p / 1点P / 1护理)或ARCHITECT或(细胞p / 0 DYN))或((Alere接近/ 10(化验* OR测试* OR分析* OR 阵列))或(Alere NEAR / 5(分类P / 1系统))或INRatio或Afinion )OR((Beckman * p / 1 Coulter near / 10(测定* OR测试* OR分析* OR 数组))或((Beckman * p / 0 Coulter)接近/ 2 AU ??? ?)或(UniCel * P / 1 DxC)或(UniCel * p / 1 DxI)OR(Beckman * near / 5 Access)或(Access * p / 1 Systeme)或(CytoFLEX OR(cyto p / 0 flex))或(UniCel * p / 1 DxH)OR((Coulter * p / 1 LH)或Coulter LH))OR((Ortho p / 0 Clinical P / 1 Diagnostics)或VITROS OR(vitros p / 1系统*)或(VITROS * p / 1 ECiQ)或ORTHOTM OR(orthotm p / 1 VISION)或(ORTHO p / 1 AutoVue *))或((仪器p / 0实验室)或HemosIL或ACLTOP OR(ACL) p / 0 ELITE)OR(GEM * P / 1 Premier)或GEM OPL)或((辐射计接近/ 10(分析 OR测试* OR分析* OR 阵列) )OR(AQT ?? p / 0 FLEX)或(ABL ?? p / 0 FLEX)或HemoCue *)OR((Nova p / 0 Biome) dical)或StatStrip OR(STAT p / 0 PROFILE *)或((Nova p / 0 Biomedical)近/ 1 Prime)或STATPROFILE *)或(((西门子p / 0医疗保健)接近/ 10(化验* OR测试* OR analy * OR array ))OR(ADVIA p / 0 Centaur)OR(Dimension p / 0 Vista)或RAPIDPOINT)))和(ud(> 20180101))(样本)
(ti(((Abbott near / 10(化验* OR测试* OR分析* OR 阵列))或(雅培p / 1点P / 1护理)或ARCHITECT或(细胞p / 0 DYN))或((Alere接近/ 10(化验* OR测试* OR分析* OR 阵列))或(Alere NEAR / 5(分类P / 1系统))或INRatio或Afinion )OR((Beckman * p / 1 Coulter near / 10(测定* OR测试* OR分析* OR 数组))或((Beckman * p / 0 Coulter)接近/ 2 AU ??? ?)或(UniCel * P / 1 DxC)或(UniCel * p / 1 DxI)OR(Beckman * near / 5 Access)或(Access * p / 1 Systeme)或(CytoFLEX OR(cyto p / 0 flex))或(UniCel * p / 1 DxH)OR((Coulter * p / 1 LH)或Coulter LH))OR((Ortho p / 0 Clinical P / 1 Diagnostics)或VITROS OR(vitros p / 1系统*)或(VITROS * p / 1 ECiQ)或ORTHOTM OR(orthotm p / 1 VISION)或(ORTHO p / 1 AutoVue *))或((仪器p / 0实验室)或HemosIL或ACLTOP OR(ACL) p / 0 ELITE)OR(GEM * P / 1 Premier)或GEM OPL)或((辐射计接近/ 10(分析 OR测试* OR分析* OR 阵列) )OR(AQT ?? p / 0 FLEX)或(ABL ?? p / 0 FLEX)或HemoCue *)OR((Nova p / 0 Biome) dical)或StatStrip OR(STAT p / 0 PROFILE *)或((Nova p / 0 Biomedical)近/ 1 Prime)或STATPROFILE *)或(((西门子p / 0医疗保健)接近/ 10(化验* OR测试* OR analy * OR array ))OR(ADVIA p / 0 Centaur)OR(Dimension p / 0 Vista)或RAPIDPOINT)))和(ud(> 20180101))(样本)
答案 0 :(得分:0)
工作解决方案可能是:
function getSecondParenthesis( text )
{
var out = "";
var nCont;
var nFound = 0;
// jump the first parenthesis, until the second one
nCont = 0;
while( nCont < text.length && nFound < 2 )
{
if( text.charAt(nCont) == '(' )
++nFound;
++nCont;
} // nCont < text.length
// just copy text jumping over
// opening and closing parenthesis,
// until reach the 0 count again
do
{
if( text.charAt(nCont) == '(' )
++nFound;
if( text.charAt(nCont) == ')' )
--nFound;
if( nFound != 0 )
out += text.charAt(nCont);
++nCont;
}
while( nCont < text.length && nFound != 0 );
return out;
}