Implementing Regular Expressions in Mathematica with J/Link

Brian G. Higgins

University of California

Abstract

Although Mathematica has a set of powerful functions that allows one to manipulate and search for patterns in strings (e.g., StringReplace, StringInsert, StringMatchQ, and so on), these functions do not support regular expressions. A regular expression (regex for short) is a compact way of describing complex patterns in texts. They can be used to search for patterns and, once found, to modify the patterns in a variety of ways. Some programming languages support the use of a few metacharacters to perform searches, but they do not have the full expressive power of regular expressions. Perl is a notable exception: regular expressions are built in as part of the language. Java 2 Standard Edition (1.4.0 and later) now supports regular expressions through the standard java.util.regex package. This presentation will discuss the object model in the regex package and show how regular expressions can be implemented in Mathematica using J/Link. The syntax of regular expressions will be explained using simple examples. Finally some applications in bioinformatics will be illustrated.