如何在< w:r>之间读取数据在文字? [英] How read data between <w:r> in text?

查看:95
本文介绍了如何在< w:r>之间读取数据在文字?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好b $ b

我想使用正则表达式解析字符串。我需要在< w:r>之间获取字符串在一个问题的字符串中。我知道如何仅在< w:t>之间获取数据使用模式< w:t>。*?< / w:t>



问题是因为< w:r>有另一个对象(< w:t>和< w:rPr>),我不知道如何在< w:r>之间获取整个字符串和< / w:r> ;.

你能帮助我吗,如何在< w:r>之间读取数据?和< / w:r>?





谢谢



Hi
I would like use regex for parse string. I need get string between <w:r> in string under a question. I know how get data only between <w:t> using pattern <w:t>.*?</w:t>

Problem is because <w:r> have inside another object (<w:t> and <w:rPr>) and I don't know how get whole string between <w:r> and </w:r>.
Can you help me, how can read data between <w:r> and </w:r>?


Thank you

  <w:p w:rsidR="006C121D" w:rsidRDefault="00A462A4">
  <w:pPr>
  <w:rPr>
  <w:lang w:val="en-US" />
  </w:rPr>
  </w:pPr>
  <w:bookmarkStart w:id="0" w:name="_GoBack" />
  <w:bookmarkEnd w:id="0" />
  <w:r>
  <w:rPr>
  <w:lang w:val="en-US" />
  </w:rPr>
  <w:t>TOPIC</w:t>
  </w:r>
  </w:p>





[edit]已添加代码块 - OriginalGriff [/ edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

首先,您提供的示例不是非结构化文本,而是格式化的xml。



我建议加载xml文档并阅读适用的元素或属性。



Google [ ^ ]可以为您提供一个良好的开端。所以,尝试一下,如果你还有问题,那么问题就会回来,有人愿意帮忙!
First of all, the example you have given is not unstructured text but formatted xml.

I would advice to load the xml document and the read the elements or attributes whichever is applicable.

Google[^] can give you a head start. So, try it out and if you still have issues, questions then come back and someone here would be willing to help!


如何在< w:r>之间获取数据和< / w:r>使用正则表达式?



就个人而言,我会选择Manas的解决方案并将文件正确处理为XML文档。你得到的结果可能会更好,更好,更易于维护。



但是...

How get data between <w:r> and </w:r> using regex?

Personally, I'd go with Manas' solution and process the file properly as an XML document. The results you will get are likely to be much, much better, and a lot more maintainable.

But...
(?<=<w:r>).*?(?=</w:r>)

应该这样做。



如果您打算使用正则表达式,请获取 Expresso [< a href =http://www.ultrapico.com/Expresso.htmtarget =_ blanktitle =New Window> ^ ] - 它是免费的,它会检查并生成正则表达式。我经常使用它,并且希望我写它!



那里到底是什么来的?[/ edit]

Should do it.

If you are going to play with regexes, then get a copy of Expresso [^] - it's free, and it examines and generates Regular expressions. I use it a lot, and wish I'd written it!

[edit]Where the heck did that come from?[/edit]


这篇关于如何在&lt; w:r&gt;之间读取数据在文字?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆