DuduSaharov
DuduSaharov

Reputation: 13

Regular expressions : How to exclude specific string inside a line

I'm trying to filter out API call names using regex. The problem is that I can't filter out specific strings from the API calls which I don't need.

In the following examples I need to filter out/cut from the API call which contains the string "sg-" (if exists) what comes after it including the string itself and the others leave untouched.

Here is the example:

GET /api/cloudsecuritygroup/sg-91f988f7/history - 443  
GET /api/cloudsecuritygroup/sg-30333554 - 443  
GET /api/cloudaccounts/secret - 443  
GET /api/audit/event-types - 443  
GET /api/user/me/iam-safe/devices - 443

The result should look like this:

cloudsecuritygroup  
cloudsecuritygroup  
cloudaccounts/secret  
audit/event-types  
user/me/iam-safe/devices

Upvotes: 0

Views: 1027

Answers (1)

guijob
guijob

Reputation: 4488

Maybe this is regex you are looking for:

(?<=GET \/api)(.+(?=\/sg-)|[^\s]+)

Check it out here

Upvotes: 0

Related Questions