"Search with pattern" problem

I'm working on a VB project. My current objective is to find all occurences in code which may cause problems with localization, because there is a new requirement fpr supporting multiple languages and locales. I have identified occurences of date conversions with string constants like this:

myDateVar = CDate("01.10.1999")

I have tried to use "Search with pattern" to find all occurences of this kind. Therefore i defined the following pattern:


where arg1 is defined as expression of System.String. When i execute the pattern R# puts also all CInt, CStr... occcurences in the find result even is i uncheck "Match similar constructs". Do i miss something or is the function buggy?

By the way, my goal is to replace all occurences by using a Date like this

myDateVar = new Date(1999, 10, 1)

Is this possible with structural find and replace?



You should be able to do this with Visual Studio's built-in Find & Replace.

  1. Ctrl+Shift+H or Edit -> Find and Replace -> Replace in Files;
  2. In the "Find what" box, enter: CDate\("{:z}\.{:z}\.{:z}"\)
  3. In the "Replace with" box, enter: new Date(\3, \2, \1)
  4. Click on the "+" next to "Find options", tick the "Use" box, and make sure the drop-down list is set to "Regular Expressions";

This assumes that the string passed to CDate always uses "." as the date separator, and is always specified in D/M/Y format.

There's a reference for the perculiar Regex syntax that Visual Studio uses on MSDN:


Hi Richard,

thanks for the hint. Your solution works perfect. I should pay more attention to the power of regular expressions in the future :).



Please sign in to leave a comment.