jQuerybeast
jQuerybeast

Reputation: 14510

Select text between two words

I am retrieving some data from the Wiktionary API. Their API parses an entire block of text with no html attributes or xml attributes.

An example of the text:

===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]]

Is it possible to select the text between ===Noun=== and ====Synonyms==== ? For example I want to end up with this:

  • 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.
  • ======================

    The entire block of text can be found here: http://pastebin.com/raw.php?i=5ETx4ivB and the results from the API can be found here in an XML form: http://en.wiktionary.org/w/api.php?action=query&prop=revisions&rvprop=content&format=xml&titles=developer

    Upvotes: 4

    Views: 219

    Answers (2)

    Arun P Johny
    Arun P Johny

    Reputation: 388436

    Can you try

    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===`
    

    Upvotes: 1

    Aaron Blenkush
    Aaron Blenkush

    Reputation: 3059

    Use indexOf() to find the positions of the substrings, then use substr() to get the string between the two positions you find.

    Upvotes: 0

    Related Questions