Brian Dunning's FileMaker Custom Functions

MatchValues ( Values ; Pattern ; StartsOrEndsOrPartialOrExact )

Return values by matching Pattern with option (Starts with, Ends with, Partial, Exact).

  Average rating: 5.0 (26 votes) Log in to vote

Koji Takeuchi   Koji Takeuchi - Show more from this author
TonicNote, Inc.
https://tonicnote.com

Share on Facebook Share on Twitter

  Sample input:
MatchValues ( "<>aa¶bb¶cc<>" ; "<>" ; "Starts" )
  Sample output:
<>aa

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

MatchValues ( Values ; Pattern ; StartsOrEndsOrPartialOrExact )
2013.02.18, Koji Takeuchi


description:
Return values by matching Pattern with option (Starts with, Ends with, Partial, Exact).
ex1.
MatchValues ( "<>aa¶bb¶cc<>" ; "<>" ; "Starts" )
= <>aa
ex2.
MatchValues ( "<>aa¶bb¶cc<>" ; "bb" ; "Exact" )
= bb
ex3.
MatchValues ( "<>aa¶bb¶cc<>" ; "b" ; "Partial" )
= bb¶cc<>
ex3.
MatchValues ( "<>aa¶bb¶cc<>" ; "b" ; "Exact" )
= ""

 

Comments

Adam   Adam, Portland, OR
Nov 8, 2014
I'm trying to use this function to replace the patternCount function in a portal filter calc, but it doesn't seem to be working. Any help would be appreciated.

I'm using this technique...

http://www.soliantconsulting.com/blog/2013/03/dynamically-filtering-filtered-portals


I want to change it so the portal only displays records that have words that start with the text being searched for.
 
Chris Van Buren   Chris Van Buren, Tintern, UK
Apr 30, 2015
Thanks for the useful CF. It was exactly what I needed!
 
Howard Schlossberg   Howard Schlossberg, FM Professional Solutions
May 21, 2020
This was exactly what I needed -- for a while. And then I came upon a situation where I had a LIST of patterns I needed to match against my list of values. To avoid creating a "wrapper" custom function that then called this one, I just modified this function to handle the case where there are multiple patterns. I should note that I've only tested this with "Starts", as that is the only one I currently needed it to work with, but I see no reason it shouldn't work for any StartsOrEndsOrPartialOrExact case. Hope this helps someone:

Case(

ValueCount( Pattern ) > 1;
/* handle multiple pattern values */
List(
MatchValues ( Values; GetValue( Pattern; 1 ) ; StartsOrEndsOrPartialOrExact);
MatchValues ( Values; RightValues ( Pattern ; ValueCount ( Pattern ) - 1 ) ; StartsOrEndsOrPartialOrExact)
);

// ************************************************************************
// ELSE run the whole thing for a single pattern
// ************************************************************************

Let (
[
pattern = GetValue ( Pattern; 1 );
target =
GetValue ( Values ; 1 ) ;
method =
Case (
not IsEmpty ( StartsOrEndsOrPartialOrExact ) ;
Lower ( StartsOrEndsOrPartialOrExact ) ;
"partial"
) ;
match =
Case (
method = "starts" ;
Left ( target ; Length ( Pattern ) ) = Pattern ;
method = "ends" ;
Right ( target ; Length ( Pattern ) ) = Pattern ;
method = "partial" ;
PatternCount ( target ; Pattern ) > 0 ;
method = "exact" ;
target = Pattern
) ;
rest =
RightValues ( Values ; ValueCount ( Values ) - 1 ) ;
more =
PatternCount ( rest ; Pattern ) > 0
] ;


Case (
match ; target
) &

Case (
match and more ; ¶
) &

Case (
more ; MatchValue
 

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: