regularExpression in SSRS report?


It looks like I could use the =System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3") in SSRS 2005 report.
But when I try to do it, =System.Text. didnot have the RegularExpressions object.
It doesn't show up in the dropdown.

I have this field in this format ((xxxxxx*)) xxxxx*, I want to grab the ((xxxx)) part using the regular expression. I want to look for (( & )) and grab everything between them.


Who is Participating?
Megan BrooksConnect With a Mentor SQL Server ConsultantCommented:
You can reference the regular expression classes in custom code. For example, if you add the function below to the "Code" section of Report Properties then you can call it with an expression like

The actual string returned by this expression is "ab".

    Function RE(ByVal p As String, ByVal i As String) As String
        Dim r As System.Text.RegularExpressions.Regex = New System.Text.RegularExpressions.Regex(p)
        Dim m As System.Text.RegularExpressions.Match = r.Match(i)
        Return m.Value
    End Function

Open in new window

planoczConnect With a Mentor Commented:
Here is a sample you can use
It is set to look for Number length from 1 to 5
Public Sub FindBetween(ByVal strIn As String)
        ' Define a regular expression for repeated Numbers. 
        Dim regexParser As Regex = New Regex("\b[0-9]{1,5}\b", RegexOptions.Multiline)
        For Each matchCurrent As Match In regexParser.Matches(strIn)
            Dim valueString As String = matchCurrent.Value.ToString
    End Sub

Open in new window

All Courses

From novice to tech pro — start learning today.