正则表达式:如何排除一行内的特定字符串
Regular expressions : How to exclude specific string inside a line
我正在尝试使用正则表达式过滤掉 API 呼叫名称。
问题是我无法从 API 调用中过滤掉我不需要的特定字符串。
在下面的示例中,我需要从包含字符串 "sg-"(如果存在)的 API 调用中过滤 out/cut在它之后包括字符串本身,其他的保持不变。
示例如下:
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
结果应该是这样的:
cloudsecuritygroup
cloudsecuritygroup
cloudaccounts/secret
audit/event-types
user/me/iam-safe/devices
也许这就是您正在寻找的 regex
:
(?<=GET \/api)(.+(?=\/sg-)|[^\s]+)
看看here
我正在尝试使用正则表达式过滤掉 API 呼叫名称。 问题是我无法从 API 调用中过滤掉我不需要的特定字符串。
在下面的示例中,我需要从包含字符串 "sg-"(如果存在)的 API 调用中过滤 out/cut在它之后包括字符串本身,其他的保持不变。
示例如下:
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
结果应该是这样的:
cloudsecuritygroup
cloudsecuritygroup
cloudaccounts/secret
audit/event-types
user/me/iam-safe/devices
也许这就是您正在寻找的 regex
:
(?<=GET \/api)(.+(?=\/sg-)|[^\s]+)
看看here