0

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
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • You just want to check one link with your regex right? – cansik Aug 06 '17 at 15:57
  • What I'm trying to do is fetch the name of the API call using regex. – DuduSaharov Aug 06 '17 at 15:58
  • Ok, but for example `audit/event-types` does not contain `sg-`. So why is it in the result too? Or could you please give a bit more specifications on how it should work? And what did you try so far? – cansik Aug 06 '17 at 16:00
  • What programming language are you using? – melpomene Aug 06 '17 at 16:01
  • I'm using SumoLogic to parse IIS logs. The reason I've provided the other examples is because I want to exclude any characters which comes after "sg-" and for the other patters which don't contain "sg-" I want them not to be affected of this filter. Basically, I'm running a search in SumoLogic and I want to parse the IIS logs and fetch the name of the API call using parse regex function. I was able to achieve it but the API calls which contain "sg-" were written like this : cloudsecuritygroup/sg- And that's what I'm trying to avoid. – DuduSaharov Aug 06 '17 at 16:07

1 Answers1

0

Maybe this is regex you are looking for:

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

Check it out here

guijob
  • 4,413
  • 3
  • 20
  • 39