Tags:
create new tag
view all tags

SID-01216: Parsing a block of text

Status: Answered Answered TWiki version: Perl version:
Category: CategorySearch Server OS: Last update: 15 years ago

Hi, my goal is to parse something like this:

FRUITAppleBEGIN a fruit that comes in red, yellow, green. FRUITAppleEnd FRUITPeachBEGIN has hair. FRUITPeachEnd FRUITNectarinesBEGIN doesn't have hair. FRUITNectarinesEnd FRUITBananasBEGIN have potassium FRUITBananasEnd

then insert what I get, i.e. "have potassium" into a row of a table corresponding to Banana.

What I have so far is something like: %INCLUDE{"pageyourcontentisin" pattern="^.*?FRUIT.*BEGIN(.*?)FRUIT.*END*.*"}%

which will include the information inside.

I am also trying:

%SEARCH{search="FRUIT.*BEGIN" topic="pageyourcontentisin" nosearch="on" multiple="on" nototal="on" regex="on" format="$pattern(^.*?FRUIT.*BEGIN(.*?)FRUIT.*END*.*)" }%

the issue is that both methods are only printing out the last instance of the pattern, i.e. "have potassium" and not all instances.

http://twiki.org/cgi-bin/view/TWiki/FormattedSearch

Here it says .* only prints the last occurance of the pattern. I tried .*?, which does the same thing. How do I grab all instances?

Sorry for the newb question--any help is much appreciated!

-- WeiJiang - 2011-06-29

Discussion and Answer

I've managed to turn up all the results I want, but now the issue is how to keep a variable that holds the names, i.e. apple, bananas, so that I can use it to dynamically generate a table with the names in one column, and the parsed text in another.

Someone suggested I search for the first instance, chop the rest of the text and put it into a string variable and continue until the whole text is parsed. But that still doesn't deal with the issue of how to get the thing represented by the wildcard in the search, i.e. "FRUIT*END..."

Any pointers would be helpful. Thanks!

-- WeiJiang - 2011-07-01

Nevermind, I can just get the word between FRUIT and END in the same way I got the content between FRUIT*BEGIN and FRUIT*END.

What is conceptualized in my mind is that I would somehow search only between FRUITappleEND and the rest of the text to find Peach and corresponding text, and loop so on until I get all the fruit and their comments...

-- WeiJiang - 2011-07-01

In order to do more sophisticated reports I recommend using TWikiForms and FormattedSearches, they are much more flexible, especially with QuerySearch.

-- PeterThoeny - 2011-07-02

      Change status to:
ALERT! If you answer a question - or someone answered one of your questions - please remember to edit the page and set the status to answered. The status selector is below the edit box.
SupportForm
Status Answered
Title Parsing a block of text
SupportCategory CategorySearch
TWiki version

Server OS

Web server

Perl version

Edit | Attach | Watch | Print version | History: r3 < r2 < r1 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r3 - 2011-07-02 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2026 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.