Greetings,
I have struggled to swap the operation of this format expression
Regular Expressions - #46 by DetlevD?
to achieve this
2009-02-03 to 03 Feb 2009
Would appreciate any help from regex experts
Thanks
George
Greetings,
I have struggled to swap the operation of this format expression
Regular Expressions - #46 by DetlevD?
to achieve this
2009-02-03 to 03 Feb 2009
Would appreciate any help from regex experts
Thanks
George
You do not say in which field you find the date.
Try an action of the type "Format value" or Convert>Tag-Tag for the unnamed field
Format string: $regexp('2009-02-03',\d+-\d+-(\d+),$1) $replace($regexp('2009-02-03',\d+-(\d+)-\d+,$1),01,Jan,02,Feb) $regexp('2009-02-03',(\d+)-\d+-\d+,$1)
in which you also replace '2009-02-03' with the fieldname.
And you have to complete the translation of month numbers into month names. I was too lazy to write all 12 and just showed 01 for Jan and 02 for Feb
Thank you, I will try this. I have been using a Comment field as my experiment field, but ultimately I want to split filename (2003-03-01-SomeTextFollows) into the Title field as 01 Mar 2003 - Some Text Follows. I have managed to achieve the text extraction and conversion and am happy I can achieve the concatenation of date and text once I have converted date format.
I would use Convert>Filename-Tag with
Format string: %year% - %title%
to get the data from the filename into the fields YEAR and TITLE
and then use this structured data to adapt the format.
Finally, you can re-write the filename with Convert>Tag-Filename (if still required).
Also, you can copy the YEAR data to TITLE with
Convert>Tag-Tag for TITLE
Format string: %year% - %title%
The final tested solution.
Convert 2009-03-02 to 2 Mar 2009
$regexp(%yourfield%,\d+-\d+-(\d+),$1) $replace($regexp(%yourfield%,\d+-(\d+)-\d+,1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%yourfield%,(\d+)-\d+-\d+,$1)
Thank you @ohrenkino for your guidance
$regexp(%yourfield%,\d+-\d+-(\d+),$1) $replace($regexp(%yourfield%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%yourfield%,(\d+)-\d+-\d+,$1)
Are you sure that this should work as expected?
If I try it with 2009-03-02 in a COMMENT field and this regular expression:
$regexp(%COMMENT%,\d+-\d+-(\d+),$1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)
I get as result 02 1 2009 and not the expected 2 Mar 2009
Even If I fix the replacement from 01,Jan to 1,Jan I only get 02 Jan 2009 as result.
BTW:
The regular expression started from @ohrenkino would work for the March example:
$regexp(%COMMENT%,\d+-\d+-(\d+),$1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1) and results in the expected 02 Mar 2009
(please note the leading zero for the day)
This regular expression would work - at least for the number-to-month replacement.
$regexp(%COMMENT%,\d+-\d+-(\d+),$1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)
But it still convert YYYY-MM-DD in DD MMM YYYY (with a leading zero in front of the day).
2009-03-02 becomes 02 Mar 2009
If the expected result should show the days 01 to 09 without leading zero, then you would need an additional $num around the number of days, something like
$num($regexp(%COMMENT%,\d+-\d+-(\d+),$1),1)...
The complete regular expression to
would look like this:
$num($regexp(%COMMENT%,\d+-\d+-(\d+),$1),1) $replace($regexp(%COMMENT%,\d+-(\d+)-\d+,$1),01,Jan,02,Feb,03,Mar,04,Apr,05,May,06,Jun,07,Jul,08,Aug,09,Sep,10,Oct,11,Nov,12,Dec) $regexp(%COMMENT%,(\d+)-\d+-\d+,$1)
Apologies, you are right, there is a missing $ here, for the 1 variable at end of this string.
$regexp(%year%,\d+-\d+-(\d+),$1) $replace($regexp(%year%,\d+-(\d+)-\d+,$1) ....
Could you please correct in my solution, I appear be unable to edit.
Agree that my expression does not remove leading zero for single digit day values, but I didn't see that as an issue, was so happy to achieve transformation ![]()
I'm not sure why you are unable to click on the
![]()
icon and edit your own solution.
But I hope I have fixed it (please double check it).
This is not a big issue, I have only added this version for future readers.
Editing of Solution not allowed? I don't see the pencil symbol on my Solution post, but I do see it on my other posts in this thread.
Solution is correct now, thank you