Regex pattern to remove all fullstops(periods) before DATE.
Hello again, sorry to be a bother, but, as title really. I've been trying to create a REGEX to remove all the dots in a string, up until the DATE, ie.
mary.had.a.little.lamb.21.03.2025 I want to read as 'mary had a little lamb - 21.03.2025'
I've been playing on regex101, and this regex works:- [.](?:\d{2}.\d{2}.\d{4})?
Removing all the fullstops, and leaving out the date part to give:-
maryhadalittlelamb
Whereupon I can substitute in a space for the stored matches to give:-
mary had a little lamb
Subsequently adding the date, complete with fullstops back in, but I can't get it to work in Advanced Renamer, it removes ALL the fullstops, not caring about the ' ?: ' non capturing reference.
Am I missing something?
Thanks.
mary.had.a.little.lamb.21.03.2025 I want to read as 'mary had a little lamb - 21.03.2025'
I've been playing on regex101, and this regex works:- [.](?:\d{2}.\d{2}.\d{4})?
Removing all the fullstops, and leaving out the date part to give:-
maryhadalittlelamb
Whereupon I can substitute in a space for the stored matches to give:-
mary had a little lamb
Subsequently adding the date, complete with fullstops back in, but I can't get it to work in Advanced Renamer, it removes ALL the fullstops, not caring about the ' ?: ' non capturing reference.
Am I missing something?
Thanks.
Reply to #1:
Yeah, I've seen that same regex irregularity in Aren regex. I don't sweat it much since I prefer JS over some forms of regex.
Anywho, this should be close to what you want. Create a Script method with this code:
zDateRegEx = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
sDate = item.newBasename.match (zDateRegEx).pop ();
sDateless = item.newBasename.replace (zDateRegEx, "");
sNewBase = sDateless.replace (/\./g, " ");
//* Debug:
console.log ("sDate: ", sDate);
console.log ("sDateless: ", sDateless);
console.log ("sNewBase: ", sNewBase);
//*/
return sNewBase + "- " + sDate;
Note that using \b and \. reduces the chances of false hits on this regex.
PS: "regex irregularity" is *totally* not a pun. ;)
Yeah, I've seen that same regex irregularity in Aren regex. I don't sweat it much since I prefer JS over some forms of regex.
Anywho, this should be close to what you want. Create a Script method with this code:
zDateRegEx = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
sDate = item.newBasename.match (zDateRegEx).pop ();
sDateless = item.newBasename.replace (zDateRegEx, "");
sNewBase = sDateless.replace (/\./g, " ");
//* Debug:
console.log ("sDate: ", sDate);
console.log ("sDateless: ", sDateless);
console.log ("sNewBase: ", sNewBase);
//*/
return sNewBase + "- " + sDate;
Note that using \b and \. reduces the chances of false hits on this regex.
PS: "regex irregularity" is *totally* not a pun. ;)
Reply to #1:
Hi,
Try using two 'Replace' methods to achieve your desired result.
First Replace method:
Replace: \.(?=\D)
Replace with: (space)
Regex: yes
This captures all dots following a non-digit character and replaces them with a space. Next, replace the remaining dot before the numeric date.
Second Replace method:
Replace: .
Replace with: -
Occurrence: First
Regex: unchecked
Hope this helps!
Hi,
Try using two 'Replace' methods to achieve your desired result.
First Replace method:
Replace: \.(?=\D)
Replace with: (space)
Regex: yes
This captures all dots following a non-digit character and replaces them with a space. Next, replace the remaining dot before the numeric date.
Second Replace method:
Replace: .
Replace with: -
Occurrence: First
Regex: unchecked
Hope this helps!
Reply to #2: Hi, thankyou for the reply, this does work perfectly!
One day I will have to try and learn JS!
One day I will have to try and learn JS!
Reply to #3:
Hi, I tried your method but while it removes the dots in the example i provided, it doesn't remove them if the string contains other numbers.
Thanks.
Hi, I tried your method but while it removes the dots in the example i provided, it doesn't remove them if the string contains other numbers.
Thanks.
Reply to #5:
I understand the real problem you omitted from your first message.
Try this:
First Replace: this captures a dot before the date and replaces it with a dash between two spaces.
Replace: \.(?=\d{2}\.\d{2}\.\d{4})
Replace with: (space)(dash)(space)
Regex: yes
Second Replace: this captures all dots before a dash and replaces them with a space.
Replace: \.(?=.*-)
Replace with: (space)
Regex: yes
I understand the real problem you omitted from your first message.
Try this:
First Replace: this captures a dot before the date and replaces it with a dash between two spaces.
Replace: \.(?=\d{2}\.\d{2}\.\d{4})
Replace with: (space)(dash)(space)
Regex: yes
Second Replace: this captures all dots before a dash and replaces them with a space.
Replace: \.(?=.*-)
Replace with: (space)
Regex: yes
Reply to #6:
Hi all,
I've been overheating my dog-brain for an hour and can't envision a way to do it in one replace. I did find these (maybe less complex) 2-replace method batches. I put quotes around each one, but of course leave the quotes out:
1)
Replace: "\."
With: " "
(Just replaces all periods with spaces)
Replace: " (\d\d) (\d\d) (\d{4})"
With: " - $1.$2.$3
(Puts in the dash and the periods in the date)
2)
Replace: "(([^\d\.]+)\.)"
With: "$2 "
(This gives you "mary had a little lamb 21.03.2025")
Replace: "(\w) (\d\d\.\d\d\.)"
With: "$1 - $2"
(That should put the dash in the right place unless you have "nn.nn" somewhere else in your filenames)
Another way to do it in script (but it won't work if there's a dash in your filename):
n = item.newBasename.replace( /\.(\d\d\.\d\d\.\d{4})/, " - $1" ) ;
newN = n.split( "-" ) ;
return newN[0].replace( /\./g, " " ) + "-" + newN[1] ;
It just replaces the period before the date with " - "; then it splits the name into two parts at that dash; then it returns the rejoined parts after replacing periods with spaces in the first part. Probably not as universal as Randy's script, but just another way to do it.
Cheers to all! :)
DF
Hi all,
I've been overheating my dog-brain for an hour and can't envision a way to do it in one replace. I did find these (maybe less complex) 2-replace method batches. I put quotes around each one, but of course leave the quotes out:
1)
Replace: "\."
With: " "
(Just replaces all periods with spaces)
Replace: " (\d\d) (\d\d) (\d{4})"
With: " - $1.$2.$3
(Puts in the dash and the periods in the date)
2)
Replace: "(([^\d\.]+)\.)"
With: "$2 "
(This gives you "mary had a little lamb 21.03.2025")
Replace: "(\w) (\d\d\.\d\d\.)"
With: "$1 - $2"
(That should put the dash in the right place unless you have "nn.nn" somewhere else in your filenames)
Another way to do it in script (but it won't work if there's a dash in your filename):
n = item.newBasename.replace( /\.(\d\d\.\d\d\.\d{4})/, " - $1" ) ;
newN = n.split( "-" ) ;
return newN[0].replace( /\./g, " " ) + "-" + newN[1] ;
It just replaces the period before the date with " - "; then it splits the name into two parts at that dash; then it returns the rejoined parts after replacing periods with spaces in the first part. Probably not as universal as Randy's script, but just another way to do it.
Cheers to all! :)
DF
Reply to #5:
My JS script does handle all dots as you wish. It makes NO assumptions about order, other digits, nor anything other than the date format.
Just sayin' ... ;P
My JS script does handle all dots as you wish. It makes NO assumptions about order, other digits, nor anything other than the date format.
Just sayin' ... ;P
Thankyou all for the replies and input!
Styb, that update does work for the use case given. Ta!
Delta Foxtrot, your JS code also works! Ta!
I now have to try and work out how to cater for DATE being in a different part of the string:-
mary.had.21.12.2025.a.little.lamb
This JS looks interesting, Never used it before, but I have a minute knowledge of C++.
Randy, your code works for this, although it creates an extra space where the date is cut. I've been studying your code with interest. I can see that variables are created on the left, to which are assigned the result of 'functions'.
I've look on the internet to get an explanation of what I believe are the key terms 'match, new, etc.
Would you be kind enough to give me a brief exaplanation of what each line is doing? (apart from the console stuff).
Ta.
Styb, that update does work for the use case given. Ta!
Delta Foxtrot, your JS code also works! Ta!
I now have to try and work out how to cater for DATE being in a different part of the string:-
mary.had.21.12.2025.a.little.lamb
This JS looks interesting, Never used it before, but I have a minute knowledge of C++.
Randy, your code works for this, although it creates an extra space where the date is cut. I've been studying your code with interest. I can see that variables are created on the left, to which are assigned the result of 'functions'.
I've look on the internet to get an explanation of what I believe are the key terms 'match, new, etc.
Would you be kind enough to give me a brief exaplanation of what each line is doing? (apart from the console stuff).
Ta.
Reply to #9:
Okay, I made the script more robust and commented the bajeezus out of it.
You can paste everything below this line into an Aren script method and it should do everything you asked for (so far).
zDateRegEx = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/); // Note that the global flag is NOT used in this case.
// Create a new JS Regex per https://regex101.com/r/lycyy9/1
sDate = (item.newBasename.match (zDateRegEx) || ["{no date!}"]).pop ();
/*
First this gets an array of any matches to that regex (Euro dates in this case)
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Global_Objects/String/match
The || ["{no date!}"] bit ensures that we always have an array, even if there was no date in the filename.
.pop() gets the last string in the array -- which will always be either the first date (if the
filename has more than one), or our default string (no date found), or something else if you alter the regex poorly.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Global_Objects/Array/pop
*/
sDateless = item.newBasename.replace (zDateRegEx, "");
// This creates a new string with everything except the first date.
sNewBase = sDateless.replace (/\./g, " ");
// This replaces all periods from that string with spaces.
sNewBase = sNewBase.trim ();
/* This removes any (stray) whitespace at the ends of that string.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Global_Objects/String/trim
*/
return sNewBase + " - " + sDate;
/* This returns a string for the new filename. It is the dotless text we made, then a space-dash-space, then the date.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Operators/Addition
*/
Okay, I made the script more robust and commented the bajeezus out of it.
You can paste everything below this line into an Aren script method and it should do everything you asked for (so far).
zDateRegEx = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/); // Note that the global flag is NOT used in this case.
// Create a new JS Regex per https://regex101.com/r/lycyy9/1
sDate = (item.newBasename.match (zDateRegEx) || ["{no date!}"]).pop ();
/*
First this gets an array of any matches to that regex (Euro dates in this case)
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Global_Objects/String/match
The || ["{no date!}"] bit ensures that we always have an array, even if there was no date in the filename.
.pop() gets the last string in the array -- which will always be either the first date (if the
filename has more than one), or our default string (no date found), or something else if you alter the regex poorly.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Global_Objects/Array/pop
*/
sDateless = item.newBasename.replace (zDateRegEx, "");
// This creates a new string with everything except the first date.
sNewBase = sDateless.replace (/\./g, " ");
// This replaces all periods from that string with spaces.
sNewBase = sNewBase.trim ();
/* This removes any (stray) whitespace at the ends of that string.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Global_Objects/String/trim
*/
return sNewBase + " - " + sDate;
/* This returns a string for the new filename. It is the dotless text we made, then a space-dash-space, then the date.
See https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe rence/Operators/Addition
*/
Reply to #10:
Thanks ever so much Randy, this will probably take me a while to digest, excellent.
As you suspected, I wanted to know how it works so that I can eventually modify it to cope with other date formats ('so far' - tee hee!) with either an 'if' or a 'switch'. Eg, dd.dd.yyyy (already done) or yyyy.mm.dd or yy.mm.dd.
I notice there are ready-made functions for Java like SimpleDateFormat, but if they're anything like the date functions in C++ i'll struggle :)
Always found it interesting why whoever came up with the 6 digit format for dates thought it was a good idea, seeing as how it could be yy.mm.dd OR dd.mm.yy, dependent upon where in the world you live :)
Once again, gratitude.
Thanks ever so much Randy, this will probably take me a while to digest, excellent.
As you suspected, I wanted to know how it works so that I can eventually modify it to cope with other date formats ('so far' - tee hee!) with either an 'if' or a 'switch'. Eg, dd.dd.yyyy (already done) or yyyy.mm.dd or yy.mm.dd.
I notice there are ready-made functions for Java like SimpleDateFormat, but if they're anything like the date functions in C++ i'll struggle :)
Always found it interesting why whoever came up with the 6 digit format for dates thought it was a good idea, seeing as how it could be yy.mm.dd OR dd.mm.yy, dependent upon where in the world you live :)
Once again, gratitude.
Reply to #11:
Hi again, so I noticed there is still an extra space when the string is:-
mary.had.21.12.2025.a.little.lamb
After a bit of reading I added this line to your script:-
sNewbase = sNewBase.replaceAll("\\s+", " ");
Which should in theory remove any double spaces. But it doesn't work?
PS It does work on that excellent website tester in your links!
Edit; I finally got rid of the extra space by using an extra 2 variables:-
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + Date;
No idea why I had to do that, I tried NewBase1 & NewBase2 as variable names, but it wouldn't work. JS is odd :)
Hi again, so I noticed there is still an extra space when the string is:-
mary.had.21.12.2025.a.little.lamb
After a bit of reading I added this line to your script:-
sNewbase = sNewBase.replaceAll("\\s+", " ");
Which should in theory remove any double spaces. But it doesn't work?
PS It does work on that excellent website tester in your links!
Edit; I finally got rid of the extra space by using an extra 2 variables:-
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + Date;
No idea why I had to do that, I tried NewBase1 & NewBase2 as variable names, but it wouldn't work. JS is odd :)
Reply to #12:
Ok, so far i've come up with this:-
reg1 = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
reg2 = new RegExp (/\b\d{2}\.\d{2}\.\d{2}\b/);
reg3 = new RegExp (/\b\d{4}\.\d{2}\.\d{2}\b/);
if (item.newBasename.match (reg1));
DateRegEx = reg1;
if (item.newBasename.match (reg2));
DateRegEx = reg2;
if (item.newBasename.match (reg3));
DateRegEx = reg3;
Date = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
Dateless = item.newBasename.replace (DateRegEx, "");
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + Date;
How far away am I? :)
Ok, so far i've come up with this:-
reg1 = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
reg2 = new RegExp (/\b\d{2}\.\d{2}\.\d{2}\b/);
reg3 = new RegExp (/\b\d{4}\.\d{2}\.\d{2}\b/);
if (item.newBasename.match (reg1));
DateRegEx = reg1;
if (item.newBasename.match (reg2));
DateRegEx = reg2;
if (item.newBasename.match (reg3));
DateRegEx = reg3;
Date = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
Dateless = item.newBasename.replace (DateRegEx, "");
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + Date;
How far away am I? :)
Reply to #13:
Ooh, i'm getting closer, silly syntax errors begone! Ok this seems to work now for some reason when it didn't before...(apart from the syntax errors in the previous version).
reg1 = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
reg2 = new RegExp (/\b\d{2}\.\d{2}\.\d{2}\b/);
reg3 = new RegExp (/\b\d{4}\.\d{2}\.\d{2}\b/);
if (item.newBasename.match (reg1))
DateRegEx = reg1;
if (item.newBasename.match (reg2))
DateRegEx = reg2;
if (item.newBasename.match (reg3))
DateRegEx = reg3;
Date = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
Dateless = item.newBasename.replace (DateRegEx, "");
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + Date;
Ta Da!
Don't mind me :)
Now to standardise the Date format output...
Ooh, i'm getting closer, silly syntax errors begone! Ok this seems to work now for some reason when it didn't before...(apart from the syntax errors in the previous version).
reg1 = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
reg2 = new RegExp (/\b\d{2}\.\d{2}\.\d{2}\b/);
reg3 = new RegExp (/\b\d{4}\.\d{2}\.\d{2}\b/);
if (item.newBasename.match (reg1))
DateRegEx = reg1;
if (item.newBasename.match (reg2))
DateRegEx = reg2;
if (item.newBasename.match (reg3))
DateRegEx = reg3;
Date = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
Dateless = item.newBasename.replace (DateRegEx, "");
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + Date;
Ta Da!
Don't mind me :)
Now to standardise the Date format output...
Reply to #14:
Congratulations!
But weird. What version of Aren are you using?
I can't duplicate the variable thing (but haven't tried much).
And your script contains an error. It shouldn't work and doesn't in Aren 4.17.
The error is in:
Date = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
"Date" is a reserved word in JavaScript (and most other languages). That's why I used "sDate".
(the "s" is a signal to other developers (and your future self) that the result is meant to be a string. It's part of an old school technique called "Hungarian Notation" -- something that has saved my butt innumerable times)
Anyway, you've got it working for now and sounds like you are starting to get the hang of JS. All good. :D
Congratulations!
But weird. What version of Aren are you using?
I can't duplicate the variable thing (but haven't tried much).
And your script contains an error. It shouldn't work and doesn't in Aren 4.17.
The error is in:
Date = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
"Date" is a reserved word in JavaScript (and most other languages). That's why I used "sDate".
(the "s" is a signal to other developers (and your future self) that the result is meant to be a string. It's part of an old school technique called "Hungarian Notation" -- something that has saved my butt innumerable times)
Anyway, you've got it working for now and sounds like you are starting to get the hang of JS. All good. :D
Reply to #15:
This is fun! : )
EDIT: It's great to see someone actually doing what I did, learning js specifically for ARen without knowing anything about it. Kath, it gets better; I sometimes even get through 10 lines of new code without an error, *and* occasionally it even does what I expect! :O
I've been working with js for over a year now, and have tens of thousand of lines of code that work, doing things that would break regex batch methods. Well, they work most of the time... Persevere! :)
END EDIT
Best,
DF
This is fun! : )
EDIT: It's great to see someone actually doing what I did, learning js specifically for ARen without knowing anything about it. Kath, it gets better; I sometimes even get through 10 lines of new code without an error, *and* occasionally it even does what I expect! :O
I've been working with js for over a year now, and have tens of thousand of lines of code that work, doing things that would break regex batch methods. Well, they work most of the time... Persevere! :)
END EDIT
Best,
DF
Reply to #15:
Randy: Thanks for the tip! I was wondering why the prefixes?!. Im using Version 4.16.
DF: I hope it's easier than trying to learn C++!
Now, I've been grappling with this for most of yesterday evening, pehaps one of you guys could tell me why it doesn't work. THe object of the excercise is to reformat the date stucture to dd.mm.yyyy. I can do this easily using ARENS basic tools, but I find myself struggling to get the script to pull out the groups required that they may be re-aranged? Thoughts?
reg1 = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
reg2 = new RegExp (/\b(\d{2})\.(\d{2})\.(\d{2})\b/);
reg3 = new RegExp (/\b\d{4}\.\d{2}\.\d{2}\b/);
if (item.newBasename.match (reg1))
DateRegEx = reg1;
if (item.newBasename.match (reg2))
{
DateRegEx = reg2;
DateRegEx = item.newBasename.replace (DateRegEx, "$4.$3.$2");
}
if (item.newBasename.match (reg3))
{
DateRegEx = reg3;
DateRegEx = item.newBasename.replace (DateRegEx, "$4.$3.20$2");
}
sDate = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
Dateless = item.newBasename.replace (DateRegEx, "");
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + sDate;
Randy: Thanks for the tip! I was wondering why the prefixes?!. Im using Version 4.16.
DF: I hope it's easier than trying to learn C++!
Now, I've been grappling with this for most of yesterday evening, pehaps one of you guys could tell me why it doesn't work. THe object of the excercise is to reformat the date stucture to dd.mm.yyyy. I can do this easily using ARENS basic tools, but I find myself struggling to get the script to pull out the groups required that they may be re-aranged? Thoughts?
reg1 = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/);
reg2 = new RegExp (/\b(\d{2})\.(\d{2})\.(\d{2})\b/);
reg3 = new RegExp (/\b\d{4}\.\d{2}\.\d{2}\b/);
if (item.newBasename.match (reg1))
DateRegEx = reg1;
if (item.newBasename.match (reg2))
{
DateRegEx = reg2;
DateRegEx = item.newBasename.replace (DateRegEx, "$4.$3.$2");
}
if (item.newBasename.match (reg3))
{
DateRegEx = reg3;
DateRegEx = item.newBasename.replace (DateRegEx, "$4.$3.20$2");
}
sDate = (item.newBasename.match (DateRegEx) || ["{no date!}"]).pop ();
Dateless = item.newBasename.replace (DateRegEx, "");
NewBase = Dateless.replace (/\.{2}/g, " ");
giraffe = NewBase.replace (/\./g, " ");
buffalo = giraffe.trim();
return buffalo + " - " + sDate;
Reply to #17:
Yes JS is easier than C++
Anyway, comments and descriptive variable names are your friends! And be very aware of capture groups when using .match().
I refactored your latest and verified that it does work with version 4.16p. Hopefully it's self documenting enough.
Enjoy! You're getting the hang of JS
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
StdDateFormat = item.newBasename; //-- This string will have the date digits shuffled as needed
//-- Warning! These formats assume Euro dates -- otherwise things might get scrambled.
rgxFourDigYearAtEnd = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/); //-- dd.mm.yyyy No capture groups for this one!
rgxFourDigYearAtBeg = new RegExp (/\b(\d{4})\.(\d{2})\.(\d{2})\b/); //-- yyyy.mm.dd
rgxTwoDigYearAtBeg = new RegExp (/\b(\d{2})\.(\d{2})\.(\d{2})\b/); //-- yy.mm.dd
if (item.newBasename.match (rgxFourDigYearAtEnd) ) {
//-- No action needed
}
else if (item.newBasename.match (rgxFourDigYearAtBeg) ) {
StdDateFormat = item.newBasename.replace (rgxFourDigYearAtBeg, "$3.$2.$1"); // yyyy.mm.dd to dd.mm.yyyy
}
else if (item.newBasename.match (rgxTwoDigYearAtBeg) ) {
StdDateFormat = item.newBasename.replace (rgxTwoDigYearAtBeg, "$3.$2.20$1"); // yy.mm.dd to dd.mm.yyyy but only for 2000's
}
//-- At this point, all dates are expected to have dd.mm.yyyy format.
sDate = (StdDateFormat.match (rgxFourDigYearAtEnd) || ["{no date!}"]).pop ();
Dateless = StdDateFormat.replace (rgxFourDigYearAtEnd, "");
NewBase = Dateless.replace (/\.{1,2}/g, " ");
NewBase = NewBase.trim ();
return NewBase + " - " + sDate;
Yes JS is easier than C++
Anyway, comments and descriptive variable names are your friends! And be very aware of capture groups when using .match().
I refactored your latest and verified that it does work with version 4.16p. Hopefully it's self documenting enough.
Enjoy! You're getting the hang of JS
vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
StdDateFormat = item.newBasename; //-- This string will have the date digits shuffled as needed
//-- Warning! These formats assume Euro dates -- otherwise things might get scrambled.
rgxFourDigYearAtEnd = new RegExp (/\b\d{2}\.\d{2}\.\d{4}\b/); //-- dd.mm.yyyy No capture groups for this one!
rgxFourDigYearAtBeg = new RegExp (/\b(\d{4})\.(\d{2})\.(\d{2})\b/); //-- yyyy.mm.dd
rgxTwoDigYearAtBeg = new RegExp (/\b(\d{2})\.(\d{2})\.(\d{2})\b/); //-- yy.mm.dd
if (item.newBasename.match (rgxFourDigYearAtEnd) ) {
//-- No action needed
}
else if (item.newBasename.match (rgxFourDigYearAtBeg) ) {
StdDateFormat = item.newBasename.replace (rgxFourDigYearAtBeg, "$3.$2.$1"); // yyyy.mm.dd to dd.mm.yyyy
}
else if (item.newBasename.match (rgxTwoDigYearAtBeg) ) {
StdDateFormat = item.newBasename.replace (rgxTwoDigYearAtBeg, "$3.$2.20$1"); // yy.mm.dd to dd.mm.yyyy but only for 2000's
}
//-- At this point, all dates are expected to have dd.mm.yyyy format.
sDate = (StdDateFormat.match (rgxFourDigYearAtEnd) || ["{no date!}"]).pop ();
Dateless = StdDateFormat.replace (rgxFourDigYearAtEnd, "");
NewBase = Dateless.replace (/\.{1,2}/g, " ");
NewBase = NewBase.trim ();
return NewBase + " - " + sDate;
Reply to #18:
Thanks Randy, works like a charm.
Now I'll have to go away and try to puzzle out where I went wrong!
But, may I ask, what version/style of JS is used within AREN, as looking round sites for info I see different 'formats'. For instance 'new' seems to be 'let' on other sites, and the syntax for matches seems different.
Is there a site I can try my scripts on that will give me more insight into where I went wrong? I found 'Codeblocks' invaluable to hunt down errors in C++(even though I never managed to get 'watches' working!) ending up doing it all in my head.
Ta.
Thanks Randy, works like a charm.
Now I'll have to go away and try to puzzle out where I went wrong!
But, may I ask, what version/style of JS is used within AREN, as looking round sites for info I see different 'formats'. For instance 'new' seems to be 'let' on other sites, and the syntax for matches seems different.
Is there a site I can try my scripts on that will give me more insight into where I went wrong? I found 'Codeblocks' invaluable to hunt down errors in C++(even though I never managed to get 'watches' working!) ending up doing it all in my head.
Ta.
Reply to #19:
Glad you got it working!
As for what version of JS, you'll have to ask Kim. All I know is that it was (will be) upgraded at versions 4, 4.17, and 4.18 -- Always improving. :)
Don't worry about "new" and "let" (not the same thing) for now for Aren.
"var", "let", and "const" are very important for general JS programming but not really needed for Aren (so far).
You'll know when to use "new" from code examples and documentation you come across; don't sweat it.
For JS developing and debugging I use VS Code with Node.js and the "Live Server" extension. But that is way overkill to start unless you are already a VS Code user.
**** For quick and dirty JS testing, use the console of your web browser (activate with ctrl-shift-k or F12, on many browsers).
**** To quickly see gross errors, use ESLint.
For example, here is your code in ESLint: https://tinyurl.com/5n73uvfs
Note that it is inside a test wrapper and that I configured ESLint to ignore two NA warnings.
You can copy-paste that code into your browser console to see it work.
**** For easier fiddling with JS code, you can use codepen.io.
Here is that same test framework in CodePen: https://codepen.io/Randy74ev/pen/JoGOBWG?editors=0012
Glad you got it working!
As for what version of JS, you'll have to ask Kim. All I know is that it was (will be) upgraded at versions 4, 4.17, and 4.18 -- Always improving. :)
Don't worry about "new" and "let" (not the same thing) for now for Aren.
"var", "let", and "const" are very important for general JS programming but not really needed for Aren (so far).
You'll know when to use "new" from code examples and documentation you come across; don't sweat it.
For JS developing and debugging I use VS Code with Node.js and the "Live Server" extension. But that is way overkill to start unless you are already a VS Code user.
**** For quick and dirty JS testing, use the console of your web browser (activate with ctrl-shift-k or F12, on many browsers).
**** To quickly see gross errors, use ESLint.
For example, here is your code in ESLint: https://tinyurl.com/5n73uvfs
Note that it is inside a test wrapper and that I configured ESLint to ignore two NA warnings.
You can copy-paste that code into your browser console to see it work.
**** For easier fiddling with JS code, you can use codepen.io.
Here is that same test framework in CodePen: https://codepen.io/Randy74ev/pen/JoGOBWG?editors=0012
Reply to #20:
Once again Randy, thankyou, you've been very informative and helpful!
Once again Randy, thankyou, you've been very informative and helpful!
Reply to #21:
You're welcome; glad to help!
You're welcome; glad to help!