Wolfram ResearchPRODUCTSPURCHASEFOR USERSCOMPANYOUR SITES
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.

m/.../

The match operator m/regex/ tests whether a string contains a substring matching the regex. For simple matches of this sort in Mathematica, use StringFreeQ.

Here is a Perl snippet for testing whether a string contains a "b" somewhere after an "a".

Here is a Mathematica version of the same test.

In[93]:= 

If parts of the matched string need to be accessed later, using $1, $2, ... in Perl, the best Mathematica function to use is normally StringCases.

Here is Perl code for extracting an error message.

Here is a Mathematica version.

In[95]:= 

Here is Perl code for extracting several subpatterns at once.

In Mathematica, this is done with StringCases.

In[97]:= 

Out[98]=

This is similar to assigning all the matches to an array using the /g modifier.

The same thing is easily done with StringCases in Mathematica.

In[99]:= 

Out[100]=


Any questions about topics on this page? Click here to get an individual response.Buy NowFree TrialMore Information



 © 2009 Wolfram Research, Inc.  Terms of Use  Privacy Policy |
Sign up for our newsletter: