Cool feature using the RegexReplaceActivity

by Henrik Nilsson 30. April 2009 13:28

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 cool???
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.

Tags: , , ,

Workflow | Forefront Identity Manager

Comments

4/30/2009 6:21:27 PM #

Brad Turner

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.

Brad Turner United States |

4/30/2009 6:50:30 PM #

Joe Zamora

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!

Joe Zamora |

5/1/2009 11:32:19 AM #

Henrik

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/

Henrik Sweden |

Comments are closed

Copyright © 2009 Henrik Nilsson
Log in

About the author

Henrik - the author Hi and welcome to Stockholm, Sweden!
I'm Henrik Nilsson and the author of this blog.
I do hope you find something interesting during your visit...


More about me...

Contact me...

This site and content is my own work and opinion, it does not necessary reflect the opinions of my employers at Cortego.

Identity Lifecycle Manager

View Henrik Nilsson's profile on LinkedIn

Followers