Java regex to extract date format out into month and year -


hi have following date string format:

june-2008

july-2008

march-2010

may enquire java regex extract out whatever month , year value separate string each. delimeter here "-" sign

any values start end of "-" sign month, after "-" sign year value.

the following achieve

string m = march    string y = 2010 

thank help!

don't use regex. use string#split():

string[] parts = "june-2008".split("-", 2); // or .split("-") string m = parts[0]; // "june" string y = parts[1]; // "2008" 

even better, use simpledateformat, , you'll have proper date work with:

dateformat df = new simpledateformat("m-y"); date mydate = df.parse("june-2008"); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -