java - Regex for date in other string -
this example string:
xzyxxy%mm%xyzxy%dd%xyyzy
i want turn regular expression. mm has in range 1-12 , dd in range 1-31. here possible strings matches regex:
xzyxxy5xyzxy28xyyzy xzyxxy11xyzxy2xyyzy xzyxxy12xyzxy31xyyzy
i'm new regular expression , first idea regex mm , dd , append other string. java method:
string getregex() { string mmregex = ""; string ddregex = ""; string regex; regex = expression.replaceall("%dd%", ddregex); regex = regex.replaceall("%mm%", mmregex); return regex; }
the problem when find regex dd , mm , append other string doesn't work.
i think maybe want doesn't have regular expressions. if want past day , month in string, use:
string answer = string.format("xzyxxy%dxyzxy%dxyyzy", 5, 28);
the again, if looking go other way, maybe use:
string date = "xzyxxy5xyzxy28xyyzy"; string dateparts[] = x.split("[^0-9]+");
then dateparts[1] "5" , dateparts[2] "28" use?
Comments
Post a Comment