测试:{"param":"success","value":"10","level":"0","error_code":"101","customer_id":"5b0e9b23e423b0d33c9f7ddfd", "purchases": "13", "last_activity_ts": "123523465"}匹配:Match 1Full match 63-104 `"customer_id":"5b0e9b23e423b0d33c9f7ddfd"`Group 1. 78-103 `5b0e9b23e423b0d33c9f7ddfd` SQL语句:select regexp_extract(field, '"customer_id":"([\w\d]+)"',1, 1) from table_namewhere field rlike '"error_code":"101"'I am trying to figure out how to extract customer ID from string that looks loke this:{"param":"success","value":"10","level":"0","error_code":"101","customer_id":"5b0e9b23e423b0d33c9f7ddfd", "purchases": "13", "last_activity_ts": "123523465"}I am trying to extract customer ID from strings that contain error code 101 with following code:select regexp_extract(field, '\"customer_id":"(.*)', 0) from table_namewhere field rlike '"error_code":"101"'But this gives me a following result:"customer_id":"5b0e9b23e423b0d33c9f7ddfd", "purchases": "13", "last_activity_ts": "123523465"}Expected result:5b0e9b23e423b0d33c9f7ddfdCould you please help me with this? 解决方案 You can use below regex:"customer_id":"([\w\d]+)"Demo : https://regex101.com/r/MEOGw8/1Test:{"param":"success","value":"10","level":"0","error_code":"101","customer_id":"5b0e9b23e423b0d33c9f7ddfd", "purchases": "13", "last_activity_ts": "123523465"}Match:Match 1Full match 63-104 `"customer_id":"5b0e9b23e423b0d33c9f7ddfd"`Group 1. 78-103 `5b0e9b23e423b0d33c9f7ddfd`SQL Statement:select regexp_extract(field, '"customer_id":"([\w\d]+)"',1, 1) from table_namewhere field rlike '"error_code":"101"' 这篇关于Impala中的REGEXP_EXTRACT的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!