# Script painless use regex match not found

**URL:** <https://discuss.elastic.co/t/script-painless-use-regex-match-not-found/319433>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [November 21, 2022, 11:22am UTC](https://discuss.elastic.co/t/script-painless-use-regex-match-not-found/319433 "2022-11-21T11:22:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![wnn](https://avatars.discourse-cdn.com/v4/letter/w/a88e4f/32.png) [@wnn](https://discuss.elastic.co/u/wnn)\
**Post date:** [November 21, 2022, 11:22am UTC](https://discuss.elastic.co/t/script-painless-use-regex-match-not-found/319433/1 "2022-11-21T11:22:58Z")

</div>

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

```auto
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;
} } 

```

---

<div class="post-metadata">

**Author:** ![wnn](https://avatars.discourse-cdn.com/v4/letter/w/a88e4f/32.png) [@wnn](https://discuss.elastic.co/u/wnn)\
**Post date:** [November 21, 2022, 12:25pm UTC](https://discuss.elastic.co/t/script-painless-use-regex-match-not-found/319433/2 "2022-11-21T12:25:37Z")

</div>

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

```auto
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;
} }

```

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [December 19, 2022, 12:26pm UTC](https://discuss.elastic.co/t/script-painless-use-regex-match-not-found/319433/3 "2022-12-19T12:26:22Z")

</div>

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