IDM PowerTips

Tagged expressions

Here is the scenario: you have a long list of dates in the format mm/(d)d/yyyy and you need to convert it to (d)d-mm-yyyy. You’ve thought about doing it by hand but then figured that would take HOURS and there has to be an easier way to do it. Well… there is! Thanks to the power of UEStudio there is an easier way! This can be accomplished using a simple regular expression replace!

The technique we will be using is a tagged expression. A tagged expression is essentially a piece of your ‘find’ string which is ‘remembered’ and used in your replace. This powerful feature has saved us a lot of time on a number of occasions.

We understand that this may not be the exact scenario however pay attention to the method used to create your own tagged expression.

Using Tagged Expressions

Evaluate the Scenario

As anyone would tell you, when doing something such as this, it is always best to work with a small sample set of data. We have created the following input sample of dates:

Using the above sample, we have created a sample of what the end result must look like:

Using tagged expressions

We are specifically going to be using a tagged expression to convert our input sample to our output sample.

We won’t go into too much detail about regular expressions here as there is extensive information in the Help file regarding regular expressions and what they are capable of. If you haven’t ever looked into Regular Expressions, take a look into this powerful feature.

Tagged Expressions:
^(…^) Brackets or tags an expression to use in the replace command. A regular expression may have up to 9 tagged expressions, numbered according to their order in the regular expression.

The corresponding replacement expression is ^x, for x in the range 1-9. Example: If ^(h*o^) ^(f*s^) matches “hello folks”, ^2 ^1 would replace it with “folks hello”.

For our date example we are going to use the following expression:

Find What: ^([0-9]+^)/^([0-9]+^)/^([0-9][0-9][0-9][0-9]^)
Replace With: ^2-^1-^3
Regular Expression checked

Here is a brief explanation of the Regular Expression syntax we are using:

^(...^)As mentioned above, brackets or tags an expression
[0-9]matches any digit 0-9
+Matches one or more of the preceding character/expression. At least one occurrence of the character must be found.
/ literal /

To further clarify what is happening with this expression, in the example of the first entry 07/6/2005:

The ^1 represents 07
The ^2 represents 6
The ^3 represents 2005

Replace all

Click on replace all and watch UEStudio convert all of your dates to the intended format.