I am new to regex
and I would like to only match the latest/last month from below strings, as we can see only 202206 should be matched and in future if there is 202207 then it should only match 202207. For matching, after researching I found I can use below regex
. However, the issue is instead of matching only the latest dates it is matching both dates. How should I make my regex
to match the latest/last month string only? Is there any if condition in regex ? I referenced this post as well. However, the regex is for Perl and not for Java. The reason I would like to get Java is because I am facing similar issue as mentioned by SO user post. My ETL tool is different.
Thanks in advance!
test1-202201
test1-202206
REGEX
/\d{4}(0[1-9]|1[0-2])/