Brian Dunning's FileMaker Custom Functions

ParseData ( theText ; theStartTag ; theEndTag ; theOccurance )

Extracts text based on a start tag, end tag, and occurance.

  Average rating: 3.9 (52 votes) Log in to vote

Hal Gumbert   Hal Gumbert - Show more from this author
CampSoftware
http://www.campsoftware.com

Share on Facebook Share on Twitter

  Sample input:
ParseData ( $thePaymentEmail ; "¶Amount: " ; "¶" ; 1 )
  Sample output:
$30.00

  Function definition: (Copy & paste into FileMaker's Edit Custom Function window)

This is great for extracting text within other text. It's especially good for extracting text from forms that are emailed. For example:

If a variable $thePaymentEmail contains:
From: foo@bar.com
To: foo@bar.com
Subject: Payment Info
Amount: $30.00
Payment Type: Discover
Item: Rockem Sockem Robot
Item: Godzilla Figurine
Order Date: 20060909

ParseData ( $thePaymentEmail ; "¶Amount: " ; "¶" ; 1 ) will return '$30.00'.

ParseData ( $thePaymentEmail ; "¶Item: " ; "¶" ; 1 ) will return 'Rockem Sockem Robot'.

ParseData ( $thePaymentEmail ; "¶Item: " ; "¶" ; 2 ) will return 'Godzilla Figurine'.

 

Comments

Carl Riedel   Carl Riedel, Curator Contender
Oct 1, 2009
Is it possible to get an example file ? I am trying to extract data from the stock price from "http://finance.yahoo.com/q?s=" & Stock::Ticker_Symbol to get the latest stock price into a FileMaker field. I have created a test file, but was unable to get it to work. My email address is carlstarus@msn.com
I would greatly appreciate your help.
Thank you and Regards,
Carl
 
Carl Riedel   Carl Riedel, Curator Contender
Nov 30, 2009
This function saved me a lot of time parsing HTML pages to extract information and insert into FileMaker fields. Realy useful and easy to use. Once understood, this is beautifuly simple.
 
Karen   Karen, USA
Mar 1, 2011
Thanks!
It works well, although when I tried to use it as a script trigger it failed to find the value.
Oddly, the trigger method works fine if I leave script debugger on. FYI I found this on a script example in the MIT scraping.pdf, so it is likely the script needs a tweak.
 
Aaron   Aaron, Portland, OR
Jul 3, 2012
Cool function. However I'm having trouble dealing with reserved characters while processing HTML source code. I've learned finally that double quotes must be preceded by a backslash, ie \" but paragraph returns aren't working -- though your example implies the par symbol should do just fine for that purpose.
 
Laf   Laf, Melbourne, Australia
Nov 27, 2012
Great Function!

Thanks heaps!
 
PeterTJ   PeterTJ, London/UK
Jun 1, 2013
Isn't 'occurrence' spelled with an 'e' in the 7th character along?
 
Phil67   Phil67, Switzerland
Mar 31, 2014
Many Thanks !!!
That's a great job.
 
Riyan   Riyan, Vancouver
Feb 29, 2016
This is a wonderful function however it causes Filemaker GO to crash every time I run it on the ipad.
Thoughts?
 
Bob   Bob
Dec 8, 2016
Really useful thanks. How would you use it to return the last value (Order Date in your example) ?

How do you define theEndTag for the very end of the text?
 
stam   stam
Sep 14, 2017
Great time saver, nicely done function.

One caveat and sharing here in case others have same issues:
when importing text files for processing, I got caught out - i was getting nil value returns from this function.
Turns out that the text files (generated in TextEdit) were using Line Feed instead of Carriage Return. Substituting LF for CR did the trick

Just added this prior to calling the function and all was well:
Substitute (theText ; char (10) ; char (13))
 
Marcus Holmes   Marcus Holmes, Swansea, UK
Sep 27, 2017
Thanks, great function that save me a load of time! :) Appreciated.
 
Marcus Holmes   Marcus Holmes, Swansea, UK
Sep 27, 2017
Hope this will help someone...or you may just think "well, that's pretty %^%$ obvious"!

Using the examples above with FM's List() function will fail on the last item, as there isn't a CR here when FM sets the List. FM's list looks like this:

deet@deet.com¶
deet2@deet.com¶
deet3@deet.com

Instead I set the list as a variable and add a custom marker for the end of each item, like this

deet@deet.com[End]
deet2@deet.com[End]
deet3@deet.com[End]

and then call "[End]" in the function, rather than "¶"
 
Nigel   Nigel, London
Jan 3, 2018
This looks potentially useful. Can it be adapted to include attachments? What would be the formula for an attached jpeg or zip.
 

Log in to post comments.

 

Note: these functions are not guaranteed or supported by BrianDunning.com. Please contact the individual developer with any questions or problems.

Support this website.

This library has been a free commmunity resource for FileMaker users and developers for 20 years. It receives no funding and has no advertisements. If it has helped you out, I'd really appreciate it if you could contribute whatever you think it's worth: