2013-03-01 106 views
4

我从维基教科书API检索一些数据。他们的API分析整个文本块没有html属性或xml属性。选择两个词之间的文本

文字的例子:

===Etymology=== 
{{-er|develop}} 

===Pronunciation=== 
* {{a|UK}} {{IPA|/dɪˈvɛləpə(ɹ)/}} 
* {{a|US}} {{IPA|/dɪˈvɛləpɚ/}} 

===Noun=== 
{{en-noun}} 

# A person or entity engaged in the [[creation]] or [[improvement]] of certain classes of products. 
# A [[real estate]] developer; a person or company who prepares a parcel of land for sale, or creates structures on that land. 
# A [[film]] developer; a person who uses [[chemical]]s to create [[photograph]]s from photograph negatives. 
# A [[liquid]] used in the chemical processing of traditional photos. 
# A [[software]] developer; a person or company who creates or modifies [[computer]] software. 

====Synonyms==== 
* {{sense|person or company who writes computer software}} [[programmer]] 

====Related terms==== 
* [[develop]] 
* [[development]] 
* [[developmental]] 

是否有可能选择文本===名词之间=== ====和====同义词? 例如,我想结束与此:

  • 一个人或实体从事创建或改进某些类别的产品。
  • 房地产开发商;准备出售土地的人或公司,或在该土地上建造建筑物的人或公司。
  • 电影开发者;使用[[化学]]从照片底片制作[[照片]]的人。
  • 用于传统照片化学处理的液体。
  • ======================

    整个文本块可以在这里找到:http://pastebin.com/raw.php?i=5ETx4ivB从API的结果可能是在这里以XML形式发现:http://en.wiktionary.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=developer

    +0

    是的,它是可能的,你是怎么到目前为止,在解析方面的尝试?它与jQuery有什么关系? – 2013-03-01 03:00:07

    +0

    也许一个Markdown库可以帮助你正确地解析... – elclanrs 2013-03-01 03:00:56

    +0

    我曾尝试以不同的方式使用正则表达式:http://jsfiddle.net/jEQQS。 jQuery被标记为不通知开发人员,我不会介意使用jQuery编码的答案 – jQuerybeast 2013-03-01 03:03:03

    回答

    2

    你可以尝试

    var start = str.indexOf('===Noun==='), end = str.indexOf('====Synonyms===='); 
    var text = str.substring(start + 11, end) // +11 since `indexof` gives the start index and you need to exclude `===Noun===` 
    
    +0

    Does not似乎工作http://jsfiddle.net/jEQQS/1/ – jQuerybeast 2013-03-01 03:10:32

    +1

    更新:http://jsfiddle.net/arunpjohny/jEQQS/2/忘记删除'===名词===' – 2013-03-01 03:14:20

    +0

    是否有可能选择两个特定单词之间的文本?例如$ Lorem Ipsum $ Joe Doe $>选择“Lorem Ipsum”。 – jQuerybeast 2013-03-03 13:12:40

    0

    使用indexOf()查找子字符串的位置,然后使用substr()获取您找到的两个位置之间的字符串。