Brian Dunning's FileMaker Custom Functions

balance ( theText ; openbracket ; closebracket ; instance )

Get text to length that balances open/close markers

  Average rating: 4.4 (42 votes) Log in to vote

Bruce Robertson   Bruce Robertson - Show more from this author

Share on Facebook Share on Twitter

  Sample input:
balance( "((a=b); (1); [ (a,b);(c;d)]); ( 1;3;4)"; "("; ")";1)
  Sample output:
((a=b); (1); [ (a,b);(c;d)])

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

Given text such as JSON or HTML or XML formatted text, look for specified instance of openbracket, then look for instance of closebracket satisfying condition that count of openbracket = count of closebracket.

Returns all text up to and including identified closebracket

Can be used with single or multi character values:
{}; (); []; ; <: :> etc.

Recursive function.
Edited 12/17/2014



Christopher Kuhn   Christopher Kuhn, Temecula
Jul 11, 2014
I found that if the openbracket and closebracket are the same character then the function returns a single character...the bracket.

I changed the function such that the location of the close bracket is AFTER the location of the openbracket....

original: p2 = Position ( theText; closebracket ; 1; $instance ) ;
change: p2 = Position ( theText; closebracket ; p1+1 ; $instance ) ;

Now, i can find quoted strings with the function :)
Bruce Robertson   Bruce Robertson
Dec 17, 2014
Christopher - thanks for the suggested mod! Incorporated in revised version.

Log in to post comments.


Note: these functions are not guaranteed or supported by 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 16 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: