In C# we can do teh following:
Code: Select all
string resultString = Regex.Replace("02/22/1997","d{1,2})/(?<day>d{1,2})/(?<year>d{2,4})b">b(?<month>d{1,2})/(?<day>d{1,2})/(?<year>d{2,4})b","${day}-${month}-${year}");
The out come of this is "22/02/1997" which reverses thet day and month. This is a fairly standard Euro/US translation.
In PowerShell the method is called and works but oes not convert the values and it seems to not detect any match cases.
Try this:
Code: Select all
$r=[regex]""
$r.Replace( "02/22/1997","d{1,2})/(?<year>d{2,4})b","${day}-${month}-${year'><strong>b(?<month>d{1,2})/(?<day>d{1,2})/(?<year>d{2,4})b","${day}-${month}-${year}")
This will produce an error on the translation patern.
Try this way:
Code: Select all
$r=[regex]""
$r.Replace( "02/22/1997","b(?<month>d{1,2})/(?<day>d{1,2})/(?<year>d{2,4})b","${day}${month}${year}")
And this:
Code: Select all
$r=[regex]""
$r.Replace( "02/22/1997","b(?<month>d{1,2})/(?<day>d{1,2})/(?<year>d{2,4})b","${day}${month}${year}")
Produce this: // as output. It is getting the replacement call but the groups are not being populated.
Any ideas?
It looks as if the method being called is not the correct one. How can we coerce it to use the correct method?
If we can use this from PoSH then many more translations are possible without using delegates and a simple RegEx test harness can be built in PoSH that will allow for simple building and testing of expressions which might be useful at times.
jvierra2009-02-22 13:36:47