0

I am using groovy regex: notification.ietf-restconf:notification.my-pma-device-notification:device-notification.device-notification.notification.~/.[A-Za-z]$/.entity-ref* for any string between notification and entity-ref but its not working.

What should be the regex for any string to exist between these two fields (groovy)?

1 Answers1

0

There are a few 'notification's in the string, assuming you mean the final one 'device-notification.notification'?

The following will capture at least one character between the strings.

def str = '''device-notification.device-notification.notification.CONTAINER-NAME.entity-ref'''  

def group = ( str =~ /(?<=device-notification\.notification\.)(.+)(?=\.entity-ref)/ ) 

assert 1 == group.count
assert 'CONTAINER-NAME' == group[0][0]​
Mike W
  • 3,853
  • 2
  • 11
  • 18
  • _'{"aggs":{ "dedup": { "terms": {"script": "[doc[\u0027notification.ietf-restconf:notification.my-pma-device-notification:device-notification.entity-ref\u0027].value,doc[\u0027notification.ietf-restconf:notification.my-pma-device-notification:device-notification.device-notification.notification.*************.entity-ref\u0027].value, doc[\u0027alarm-identity\u0027].value].join(\u0027_\u0027)", "lang": "groovy", "valueType": "string", "null": true }, "aggs": { "dedup_docs": { "top_hits": { "size": 1 } } } } } } '_ – Rajat Gupta Apr 21 '17 at 10:33
  • This is my elastic query for which the starred (********) container name keeps on changing for different docs. I want a regex for any string that can happen at the place if starred (********)part. – Rajat Gupta Apr 21 '17 at 10:37
  • Amended to accommodate periods – Mike W Apr 21 '17 at 10:58
  • Does your full data actually have the unicode as per the pasted example e.g. \u0027 in it or is this how it's ended up after pasting here? – Mike W Apr 21 '17 at 11:54
  • Its in unicode only and as we are using a curl command to fetch data from elastic hence its in unicode. – Rajat Gupta Apr 21 '17 at 12:15
  • Its working on underscore (_) i.e CONTAINER_NAME but if we put a hyphen like CONTAINER-NAME. it didn't worked. Error -> Impossible to parse JSON response: SyntaxError: Unexpected token . in JSON at position 231. – Rajat Gupta Apr 21 '17 at 13:19
  • Okay so it now matches at least 1 of anything – Mike W Apr 21 '17 at 13:33
  • There is some problem with hyphen in the string. I am also looking for the solution. If you could also come up with some solution it will be a great help. Thanks in advance. – Rajat Gupta Apr 21 '17 at 13:57