What are, and how do I use Mathematica's string matching and replacement tools?
|
There are three different mechanisms provided for matching string patterns in Mathematica. Each of these must be used within functions that are equipped to handle strings. You cannot, for instance, use:
to any effect. Instead you would use:
Simple wildcard matching:
Example: Wildcards (or "metacharacters") do not work natively in functions such as Regular ExpressionsSince version 5.1 Mathematica supports regular expressions. I am not an expert on regular expression use, and detailed usage information is readily available in both the Mathematica documentation and elsewhere, so I leave it to the reader to explore. RegEx is powerful, and popular with those doing a lot of string manipulation, especially for performance. StringExpressionAlso since version 5.1 there is a paradigm of using familiar Mathematica expression patterns for strings, along with a multitude of special named patterns, within a
A major advantage of this new paradigm is that you can use most of the Mathematica pattern elements you should already be familiar with, such as Here is a contrived replacement on the start of Lorem ipsum using
|
|||||||||||||||||
|
|
Mr.Wizard's answer is of course a nice overview. But one can also answer this question by pointing to the documentation - and I don't mean this as a drive-by answer, but as an actually worth-while activity: For a nice coherent exposition of all the string matching functionality, do the following:
Navigate through the sections indicated in this screenshot:
It is a well-written overview, I think. |
|||
|
|




