Brian Dunning's FileMaker Custom Functions

ExtractPortion ( textField ; prePortion ; postPortion )

Extract a portion of a text field

  Average rating: 4.0 (38 votes) Log in to vote

Doug Elam   Doug Elam
US Home Systems, Inc.
http://www.ushomesystems.com/

Share on Facebook Share on Twitter

  Sample input:
ExtractPortion ( "http://www.MyHappyPlace.com" ; "www." ; ".com" )
  Sample output:
MyHappyPlace

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

The "middle" function is nice, but it requires you to know how many characters you want to extract. Sometimes, you don't know this, so you have to make complicated calculations to extract data. This is a simple function to extract data between point A and point B.

 

Comments

Daniel Wood   Daniel Wood, Digital Fusion Ltd
Sep 22, 2010
Note that this extracts the contents between the first occurrences of prePortion & postPortion in the text.
 
Mike Beargie   Mike Beargie, MainSpring, Inc.
Sep 30, 2017
This function actually fails in instances where the first occurrence of the postPortion is before the first occurrence of the prePortion.

EG:
<div class='test'>some content</div>
<div class='test2'>some content</div>

If I run:
ExtractPortion ( thatfield ; "<div class='test2'>" ; "</div>" )

it will fail due to the first "</div>" occurrence.

You can correct this in changing:
end = Position ( text ; postPortion ; 1 ; 1 ) - 1 ;

to this:
end = Position ( text ; postPortion ; start ; 1 ) - 1 ;
 
Carl Riedel   Carl Riedel, Curator Contender
Mar 17, 2020
Any way to make this a recursive function? Does anyone have a suggestion? I need to get multiple instances from a text field.
 
Kevin B   Kevin B
Aug 18, 2022
Can the 'prePortion' and 'postPortion' values include quotation marks, ie, "?
 

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: