Hello all,
I'm trying to use Regex (in this case) to convert phone numbers to the same format
Matching works fine via "Text Operation-> Extract: Regex" but I would also like to use Regex REPLACE
I want to use this to reformat/normalize phonenumbers like I can on regexr.com for example
See screenshot, top window is the match, below is the replace
Does anyone know how I can get this to work in TA?
BTW I think I can also acomplish it with a PowerShell command like this (did not try it yet) I saw on another forum
'0271112222' -Replace '(?:0)(2\d)(?:\s)(\d{3})(?:\s)(\d{3,4})', '+64 $1 $2 $3'
But i'd rather use a "normal" TA option for this

Any ideas?
Edwin
- DDaniel Horton @daniel.horton
Hi Edwin,
You could use the Script options in ThinkAutomation to call a Regex.Replace function available to the .Net library via C#. Here is a sample from Microsoft - https://learn.microsoft.com/en-us/dotnet/api/system.text.regularexpressions.regex.replace?view=net-7.0
Here is the code I used to replicate their example:
using System; using System.Text; using ThinkAutomationCoreClasses.Scripting; using System.Text.RegularExpressions; public class ThinkAutomationScript { public string execute(currentMessage message) { try { // Action execution code // Get extracted fields/variable values using message.GetValue("name") // Set extracted fields/variable values using message.SetValue("name","value") string input = "This is text with far too much " + "white space."; string pattern = "\\s+"; string replacement = " "; string result = Regex.Replace(input,pattern,replacement); return result; } catch (Exception e) { // Pass the error back to the automation log message.AddErrorToLog(e.Message); return ""; } } }
Here is the console output from the call:
Here is my output in ThinkAutomation's logs:
- DIn reply toisedwinr⬆:Daniel Horton @daniel.horton
Based upon this requirement we will be adding a Replace Regex function to our Text Operation Action. This will be available in our next release.
- IIn reply toisedwinr⬆:isedwinr @isedwinr
Wonderful! thx for both answers!
regards,
Happy customer ;)