Cool feature using the RegexReplaceActivity

April 30, 2009 at 1:28 PMHenrik Nilsson

The RegexReplaceActivity that is introduced in the Cortego ILM 2 Workflow Activity Library is using the Regex class of System.Text.RegularExpressions namespace and by using the Replacement parameter of the Replace function we could actually do some real cool stuff. The Replacement parameter of the Replace function is translated into the Replacement property of the RegexReplaceActivity and there is no requirement the Replacement parameter must contain a plain text, it could in fact contain a replacement pattern as well and here is an example taken from the MSDN - Regular Expressions Examples used to change the format of dates. Please notice it's just an example, you're the one that must know how actual values are formatted and I don't know if using the EmployeeEndDate attribute with this example is appropriate.

Replace dates of the form mm/dd/yy with dates of the form dd-mm-yy.

Input value (from Expression): 04/30/09 or 04/30/2009 (there's a 2 to 4 characters quantifier for year in the Regex Pattern)
RegEx Pattern: \b(?<month>\d{1,2})/(?<day>\d{1,2})/(?<year>\d{2,4})\b
Replacement: ${day}-${month}-${year} 

Regex Replace MDYToDMY  

Output value (Destination expression): 30-04-09 or 30-04-2009 – isn’t that cooljQuery15207980085869857615_1318365216111?
What happens is that the input data is captured into variables that are then used to format a new value.

Realize what you could do with this, you could in fact simply extract parts from or format input data to what ever you like!
A good source for more info about regular Expressions is .NET Framework Regular Expressions.

Posted in: Forefront Identity Manager | Workflow

Tags: , , ,

Comments (3) -

Awesome man, Regular Expressions are extremely powerful and as long as you can navigate the patterns you can keep from having to build monolithic functions for specific actions; a RegEx is flexible as you've demonstrated.

Reply

Joe Zamora
Joe Zamora says:

Wow, good stuff!  Here's an online resource for testing your regular expression capture groups:  http://gskinner.com/RegExr/.  If you enter your regex above, and then enter the date (04/30/2009), it will highlight the pattern that's matched.  You can then hold your mouse over the pattern and it will show you the groups that it captured.  Keep up the great work!

Reply

Thanks guys!
Joe, I've tried the online regex editor and it's ok but it can't resolve captured group names very well. I can recommend everyone ty use Regulator that is a great tool for editing Regular Expressions and the best of all, it's free!!!

http://sourceforge.net/projects/regulator/

Reply

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading