Single hive query to extract a piece of string

Viewed 68

I have a column data "testdata" like this "NEW /abc/testapp/v1 POST/6.0" and I want to retrieve the output as "/abc/testapp/v1"

I am able to retrieve the data starting (/abc/testapp/v1 POST/6.0) like this

select regexp_extract(testdata,'^(.*?)(?:/)(.*)$', 2) from tablename;

But not sure how to strip the POST/6.0 part in the same query.Can someone please help here?

2 Answers

You could start from the first slash and take everything until the next space:

regexp_extract(testdata, '(/[^\\s]+)', 0)

Try any of the following

regexp_extract(testdata,'\\S+', 0, 2)

-

regexp_extract(testdata,'/\\S+', 0)

-

regexp_extract(testdata,'\\s+(\\S+)', 1)
Related