With the 4.2 release just around the corner, I wanted to highlight another contributions from the community – specifically in this case, Regular Expressions. This feature was contributed by Julius Friedman. 

Regular Expressions

This is desktop compatible although some features like Capture have a more limited scope (i.e. not all the methods are there).  A typical user scenario might be parsing a stream from a serial port like a wireless modem.

This implementation is derived from the Jakarta Apache Library for regular expressions, originally written in Java.  Any ‘missing features’ can be completed over the next few months with your help and feedback.

The code is available in the community branch of the CodePlex branch of the community distribution and can be found under the System Assemblies directory (%SPOCLIENT%\Framework\Core\System\RegularExpressions).  Test Cases are also provided under the test directory. 

Here is a simple example of the Regular Expression taken from our automated tests.

public MFTestResults RegExpTest_3_Substring_Test_0()
{
    bool testResult = false;

    String expected, actual;

    Regex regex;

    string message;

    try
    {
        Log.Comment("Test subst()");
        regex = new Regex("a*b");
        expected = "-foo-garply-wacky-";
        actual = regex.Replace("aaaabfooaaabgarplyaaabwackyb", "-");
        message = "Wrong result of substitution in\"a*b\"";
        testResult = TestTestsHelper.AssertEquals(ref message, ref expected, ref actual);

        Log.Comment("Test subst() with backreferences");
        regex = new Regex("http://[.\\w?/~_@&=%]+");
        expected = "visit us: 1234<a href=\"http://www.apache.org\">http://www.apache.org</a>!";
        actual = regex.Replace("visit us: http://www.apache.org!", "1234<a href=\"$0\">$0</a>");
        message = "Wrong subst() result";
        testResult = TestTestsHelper.AssertEquals(ref message, ref expected, ref actual);

Thanks Julius!!