vendredi 22 juin 2018

regex for symbol or nothing

I have a string where I need to parse the values such that it some times exist between[''] and sometimes not.

Eg:

Input
    1. blah .... REASON: ['elm H1MM_rr'], blah ....
    2. blah .... REASON: elm H1MM_rr, blah .... 
    3. blah .... REASON: elm H1MM_rr. 
    4. blah .... REASON: ['elm H1MM_rr']. 

The elm H1MM_rr is just an example here. It could be any string after REASON:

I tried REASON: ([^,. ]+)")but this still not working for ['']

Output I am looking for = elm H1MM_rr

Can some one suggest me a regex(java pattern) which can work for both strings ?

Aucun commentaire:

Enregistrer un commentaire