A Binding is the result of matching a regular expression against a string. A Binding represents the bindings of match variables for a specific match of a regular expression and string. Match variables are referred to as capturing groups in Java or Perl regular expressions.
:-) var regex = //hello/;
:-) regex;
There is 1 result
java.util.Pattern@.....
:-) regex.findMatch( "hello" );
There is 1 result
org.millscript.millscript.datatypes.Binding@....
From a binding you can obtain the regular expression and original string used in the match when constructing this binding, the sub-section of the original string this binding matches and all of the match variables this binding represents. e.g.
:-) var regex = //hello(.*)you/;
There are 0 results
:-) var binding = regex.findMatch( "hello there you" );
There are 0 results
:-) binding.bindingMatchCount;
There is 1 result
1
:-) binding.bindingMatchVar( 1 );
There is 1 result
" there "
A Binding can also be indexed using the standard square bracket index
syntax. The index action for a binding is the same as if you were to
call the bindingMatchVar function, you will get the
match variable for the specified index. e.g.
:-) var regex = //hello(.*)you/;
There are 0 results
:-) var binding = regex.findMatch( "hello there you" );
There are 0 results
:-) binding[ 1 ];
There is 1 result
" there "
Note that unlike other languages, like Perl or Java, there is no
zero'th match variable. In those languages you could use an index of
zero to obtain the entire matched string. In MillScript you need to
use the bindingMatched function instead.