Script painless use regex match not found

i want find a word from my filed.i use the filed.keyword .but match not found
def m=/.*[0-9]+/.matcher("2020年11月");
i want get a result = 202011,but the true result is not match;
so,my friend,please help me;thank you very much

this is all my script

def dateStr=doc['date.keyword'].value;
 if(dateStr!=null&&dateStr!=''){
def m=/.*[0-9]+/.matcher(dateStr); 
 if(m.matches()){
return Integer.parseInt(m.group());
}else{
return 0;
} } 

i reslove this question;
matches is match all;
so should use find
for example:

def dateStr=doc['date.keyword'].value;
 if(dateStr!=null&&dateStr!=''){
def m=/.*[0-9]+/.matcher(dateStr); 
 if(m.find()){
return Integer.parseInt(m.group());
}else{
return 0;
} }

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.