How to change date and month into word

A swapping-ground for Regular Expression syntax

Re: How to change date and month into word

Postby lalajee » Sun Jun 27, 2021 3:52 pm

Luuk wrote:This will all be easy for the RegEx(1) to conduct, except that Im not understanding about how many total-words?
Do you describe that there should be "at least one-word on each side of the date"?? or maybe do you describe...
"at-least/only 2-words before the date, and at-least/only 2-words after the date"? (because 1st example giving 3 after the date).

Also, Im guessing that "word" does not repeat "same word" four different times, so it could be like "word1 word2 date word3 word4".
Sorry for the confusion in the first answer, because I was copy/pasting from another post, but not really understanding the match.
But its fixed now, so all of the dates do get matched, but I still need to understand about total-words before giving an example.


I understand what you mean now.

I have file name which has 60-100 letters word then the date and then another 60-100 letter word.

The beginning word and the end word can be up to 255 letters.

If I can do any length for words then that would be great.

My only interest is that I would like to convert the date into following format YYYY MM DD

21 -> 2021
22 -> 2022

91 -> 1991
99 -> 1999
lalajee
 
Posts: 8
Joined: Wed Jun 23, 2021 11:09 am

Re: How to change date and month into word

Postby Luuk » Mon Jun 28, 2021 4:31 am

Im thinking this will conduct much better, but just in case, here is all of the conditions Im thinking...

1) All dates must be in the format yy mm dd (but mm or dd can also be 1-digit)
2) yy must range from 80-21.
3) mm must range from 01-12, but the leading zero is optional for 1-9.
4) dd must range from 01-31, but the leading zero is optional for 1-9.
5) Date must be space-separated away from words on both sides, words can be 1-or-more characters.
6) The minimum number of words is two, one on each side of date, and the words dont need to repeat.

First to put a checkmark in "v2", then its a very long "Match" like...
(.+ ([8901][\d]|2[01]) (0?[1-9]|1[0-2]) )([1-9] .+)(?X)(.+ ([8901][\d]|2[01]) )([1-9] (0[1-9]|[12]\d|3[01]) .+)(?X)(.+ )([01]\d |2[01] )((0[1-9]|1[012]) (0[1-9]|[12]\d|3[01]) .+)(?X)(.+ )([89]\d )((0[1-9]|1[012]) (0[1-9]|[12]\d|3[01]) .+)(?X):01(?X):02(?X):03(?X):04(?X):05(?X):06(?X):07(?X):08(?X):09(?X):10(?X):11(?X):12

With a very long "Replace" like...
${1}0$4(?X)${1}0$3(?X)${1}20$2:$3(?X)${1}19$2:$3(?X)Jan(?X)Feb(?X)Mar(?X)Apr(?X)Mai(?X)Jun(?X)Jul(?X)Aug(?X)Sep(?X)Okt(?X)Nov(?X)Dez

Since the 'Match' has 16-matches, it was too long to make it fit onto 1-line, so I made it much smaller to fit with the colors.
The 16 replaces isnt so long, so Im only making the last 12 much smaller, because thats the easy part for the month words.
The first 4 is to be the most important, because the last 12 tiny parts just convert :Month# ===> MonthWord.
Also the browser can make it bigger for the eyesight, but I dont know if it can get properly copy/pasted when being bigger?

Match/Replace1 converts d ==> dd by prefixing 0.
Match/Replace2 converts m ==> mm by prefixing 0.
Match/Replace3 converts yy ==> yyyy by prefixing 20 and converts mm ==> :mm
Match/Replace4 converts yy ==> yyyy by prefixing 19 and converts mm ==> :mm
The last 12 just convert :mm ==> MonthWords

This how it likes to conduct the renames...
word1 21 8 14 word2 ==========> word1 2021 Aug 14 word2
word1 21 06 23 word2 =========> word1 2021 Jun 23 word2
word1 99 7 04 word2 ==========> word1 1999 Jul 04 word2
word1 21 04 23 word2 =========> word1 2021 Apr 23 word2
word1 word2 97 1 9 word3 ======> word1 word2 1997 Jan 09 word3
word1 word2 91 9 21 word3 =====> word1 word2 1991 Sep 21 word3
word1 99 14 23 word2 =========> (no rename, mm out of range)
word1 00 02 32 word2 =========> (no rename, dd out of range)
word1 79 8 14 word2 ==========> (no rename, yy out of range)
word1 22 12 25 word2 =========> (no rename, yy out of range)
00 1 1 =======================> (no rename, no words)
80 08 14 word1 ===============> (no rename, no leading word)
word1 00 08 14 ===============> (no rename, no trailing word)
Luuk
 
Posts: 320
Joined: Fri Feb 21, 2020 10:58 pm

Previous

Return to Regular Expressions