Click here to Skip to main content
15,884,628 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am new to regex and at a loss as to how to start this thing.  There's a thread with similar words in the title, except it is not about regex. 

I want to capture the month in number (1 - 12) and replace it with month name (Jan - Dec). 

I use a TEXT EDITOR for search and replace. I have successfully used regex for a lot of replacements, except this one. So, I couldn't use arrays, dictionaries, functions, etc. 

How could I accomplish the above? If then? How?


What I have tried:

I'm new to regex and don't know where to start with this problem.
Updated 15-Dec-22 6:12am

1 solution

Basically, don't use a regex: they are text processors, not programming languages, and while it might be possible to do what you want in a regex, it'd be horribly complicated and very difficult to understand or change later - when you met US date, or ISO instead of European date format for example. Or when you need to do it for a different language maybe.

A much better solution is use java code to convert the date to a Date object[^] and then convert that to a string using the month name: How to Format Date to String in Java 8 [Example Tutorial] | Java67[^]

A Regex is powerful tool, but so is a hammer: you should only use them when it is appropriate!
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900