2016-03-10 178 views
0

我在html中有一个非常大的字符串。我想把它分成Java相等部分,从<span></span>在Java中将字符串拆分成相等部分

我使用正则表达式以下,但没有得到正确的结果:

<span class='ocrx_word'(.*?)<\/span> 

任何人都可以指导我。谢谢!

字符串为:

<span class='ocrx_word' id='word_1_1' title='bbox 577 190 656 222; x_wconf 72' lang='eng' dir='ltr'>ABC</span> <span class='ocrx_word' id='word_1_2' title='bbox 671 190 854 232; x_wconf 69' lang='eng' dir='ltr'>Company</span> <span class='ocrx_word' id='word_1_3' title='bbox 2011 190 2098 222; x_wconf 81' lang='eng' dir='ltr'>SHIP</span> <span class='ocrx_word' id='word_1_4' title='bbox 2110 190 2177 222; x_wconf 84' lang='eng' dir='ltr'>TO:</span> <span class='ocrx_word' id='word_1_5' title='bbox 2192 190 2261 222; x_wconf 69' lang='eng' dir='ltr'>XYZ</span> <span class='ocrx_word' id='word_1_6' title='bbox 2276 190 2461 232; x_wconf 70' lang='eng' dir='ltr'>Company</span> 
    </span> 
+0

我强烈建议使用Jsoup这样的东西 – TheLostMind

+0

我认为你的文本中缺少一个开口范围标记。无论哪种方式你的正则表达式获得6场比赛。将一个字符串分解为相等部分是什么意思? – Armando

+0

分成相等部分表示:结果如下: ABC公司

回答

0

变化的正则表达式是这样的:

<span\s*(class='ocrx_word'(.*?))<\/span> 

结果:

enter image description here

+0

当我尝试按照使用建议使用上述正则表达式时:。我没有得到预期的结果。你能告诉我你使用了哪一种工具吗? –

+0

@sumeetkumar Regex101.com – VVN

0

试试这个正则表达式

(<span class='ocrx_word'(.*?)<\/span>) 
+0

没有得到预期的结果:我希望像这样的结果来自字符串html ABC公司

+0

可能不清楚你真正想要什么。我以为你想分割HTML并分别获得每个span标签。这不是你需要的吗? – dishan