2013-03-01 107 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()獲取您找到的兩個位置之間的字符串。