Regex (REGular EXpressions) is commonly used in command-line tools, such as grep or sed, in order to search for a pattern or to search and replace a pattern.
Regular expressions are a powerful tool whenever there's a "free form" string that needs to be analyzed, or an input from a source that may or may not provide exactly formatted input. Regex is perfect to extract useful bits and pieces from it.
In RimStone, Regex is a built-in feature via match-regex statement. Here's an example of using it in a server application:
// Use backreferences to swap two words,
// with "Reverse order word" as a result
match-regex "(word)\\s+(order)" \
in "Reverse word order" \
replace-with "\\2 \\1" \
result res
print-out res new-line
RimStone regex has a powerful "cache" clause which allows for regex pattern to be parsed once into a binary representation and used over and over without parsing again. In our tests, this often results in five times (5x) or more speed up! This makes it perfect for server applications where performance is paramount.
RimStone is overall built for performance, with LTO (Link Time Optimization) built-in across the board, and with generated C code used to create high-performance native applications. No Virtual Machines, no p-code, just native executables. On top of that, RimStone is a memory-safe language.
The full regex example, with detailed instructions, can be found here.
Top comments (0)