The simple string matcher.
The simple string matcher.
Attempts to match the input string to the given interpolated patterns via a naive globbing, that is the reverse of the simple interpolator.
Here is an example usage:
val s"Hello, $name" = "Hello, James"println(name) // "James"In this example, the string "James" ends up matching the location where the pattern$name is positioned, and thus ends up bound to that variable.
Multiple matches are supported:
val s"$greeting, $name" = "Hello, James"println(greeting) // "Hello"println(name) // "James"And thes matcher can match an arbitrary pattern within the${} block, for example:
val TimeSplitter = "([0-9]+)[.:]([0-9]+)".rval s"The time is ${TimeSplitter(hours, mins)}" = "The time is 10.50"println(hours) // 10println(mins) // 50Here, we use theTimeSplitter regex within thes matcher, further splitting the matched string "10.50" into its constituent parts