Please note that VisualCron support is not actively monitoring this community forum. Please use our contact page for contacting the VisualCron support directly.


tech@m2mediagroup.com
2017-07-14T16:50:17Z
Banging my head against this so much that my brain basically just shuts down whenever I look at it anymore.

We have a files that are in the following name format: #####_TEXT12345.pdf where the first set of #'s is a changing 5 digit number and the Text section following the underscore can be between 1-5 Alpha characters and the following number is a 5 digit number.

We need to rename this to: #####_YYMMDD_00_205 ITEXT12345.pdf. Basically we are inserting the date stamp and the custom "_00_205 I" inbetween the two original parts of the file name.

I am guessing Regex is needed for this so we can group it up. But at this point my brain is fried trying to get it to work. I have used similar renaming variables to get other files to rename, but they are in a different original format with a different rename outcome.

Here is what i came up with to start: {REGEX(MatchGetGroup|{NEWNAME()}|([0-9]+_)([A-Z]+[0-9]+\.pdf)|1)} But that only gets me the first part of the file name, i cant insert or get the rest of the file name into it.

Thanks in advance.
Sponsor
Forum information
thomas
2017-07-16T19:47:57Z
Seems to me that a simple replace should work here. You basically want to replace "_" with "_YYMMDD_00_205 I". I don't have access to VC right now, so I can't test it. I can have a quick look at it tomorrow.




thomas
2017-07-17T08:07:15Z
Just tested. This should work:

{STRING(Replace,#####_TEXT12345.pdf,_,_{DATEFORMAT(yyyyMMdd)}_00_205 I)}
tech@m2mediagroup.com
2017-07-17T18:16:29Z
Originally Posted by: thomas 

Just tested. This should work:

{STRING(Replace,#####_TEXT12345.pdf,_,_{DATEFORMAT(yyyyMMdd)}_00_205 I)}



Thank you! Apparently I cannot switch between complex and simple tasks after weeks of the former.

Gary_W
2017-07-18T23:07:10Z
If you want to perform strict format checking and enforce the format of other parts of the filename, and not just replace the first underscore, you may still want to use REGEX REPLACE though. This example will perform the replace ONLY if the filename string starts with exactly 5 digits followed by an underscore, followed by 1 to 5 alphabetic characters, followed by exactly 5 digits and then ".pdf". The parts of the string to "remember" are grouped within parenthesis and are referenced numerically left to right. So the replacement string then is the first remembered group (referenced with a dollar sign), the underscore and the date along with the fixed string, then the second remembered group. Note if the exact pattern is not matched, the replacement is not performed and the original string is returned. This may not be the desired action. Test by deleting one of the numbers from the front of the filename or adding characters to the alpha part after the underscore.

{REGEX(Replace|12345_TEXT19345.pdf|^(\d{5})_([A-Za-z]{1,5}\d{5}.pdf)|$1_{DATEFORMAT(yyMMdd)}_00_205 I$2)}
Scroll to Top