【解決方法】正規表現: 月番号を名前に置き換えます


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?

(\d{2}\/(\d{2})\/\d{4})

私が試したこと:

私は正規表現が初めてで、この問題をどこから始めればよいかわかりません。

解決策 1

基本的に、正規表現は使用しないでください。これらはテキスト プロセッサであり、プログラミング言語ではありません。正規表現で必要なことを行うことは可能かもしれませんが、それは恐ろしく複雑で、後で理解または変更するのが非常に困難です。たとえば、ヨーロッパの日付形式ではなく、米国の日付、または ISO を満たしています。 または、おそらく別の言語でそれを行う必要がある場合。

はるかに優れた解決策は、Java コードを使用して日付を 日付オブジェクト[^] 次に、月の名前を使用して文字列に変換します。 Java 8 で日付を文字列にフォーマットする方法 [Example Tutorial] | | Java67[^]

正規表現は強力なツールですが、ハンマーも同様です: 適切な場合にのみ使用してください!

コメント

タイトルとURLをコピーしました