• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1363
  • Last Modified:

reporting service regular expression



=System.Text.RegularExpressions.Regex.Replace(Fields!Phone.Value, "(\d{3})[ -.]*(\d{3})[ -.]*(\d{4})", "($1) $2-$3")

when i add the expression i get a squerrel underline at "Replace"

i think i need to add a reference but which ?

  • 3
  • 3
1 Solution
No, you can use it without a reference.
In tis instance the red squiggle is an SSRS problem, not a problem with your code - it can't parse the .Net framework and validae the function name at design time, so it squiggles. It does the same thing with custom code functions.
If you try and run the report it should work fine.
vbturboAuthor Commented:
Using this in my expression generation i just get errors down the column rows

'format and convert date to string
'match all strings that is = 01-01-0001 and replace them with string = test
=System.Text.RegularExpressions.Regex.Replace(Fields!udstedelsesdato.Value, ("\b01-01-0001\b") , "test"))

where am i dropping the ball ?

vbturboAuthor Commented:
=System.Text.RegularExpressions.Regex.Replace(Fields!udstedelsesdato.Value, "\b01-01-0001\b" , "test").ToString()

produces this error : #Error

though i have validated the regex expression and it works fine
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

You've got a few too many parenthesis in there, try this
  =System.Text.RegularExpressions.Regex.Replace(Fields!udstedelsesdato.Value, "\b01-01-0001\b", "test")

However, that assumes that your udstedelsesdato field is a string, formatted exactly as you expect. If you combine your two statements you get
  =System.Text.RegularExpressions.Regex.Replace(CDate(Fields!udstedelsesdato.Value).ToString("dd-MM-yyyy"), "\b01-01-0001\b", "test")

Which I think is what you're after
Try using a proper date not in the year 0001
I think SSRS will generate a cast error as it doesn't recognise 0001 as a valid year
vbturboAuthor Commented:
<Try using a proper date not in the year 0001
<I think SSRS will generate a cast error as it doesn't recognise 0001 as a valid year

this is because its a null value.
but it get represented as "0001" in the report (01-01-0001)

but your expression works great....thanks
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now