负面的lookahead Regex for Apache Mod cookie-保持某些cookie

发布于 2025-01-19 14:39:39 字数 547 浏览 3 评论 0原文

尝试修改 apache 请求标头指令,我需要使用负向前看正则表达式来仅保留某些 cookie。

测试字符串

someCookie=someValue; anotherCookie=yada61; cookieToKeep1=myValue; cookieToKeep2=myValue2; lastCookie=yada1

尝试删除除 cookieToKeep1cookieToKeep2 之外的所有 cookie。

我可以使用下面的正则表达式,但只匹配名称,而不匹配 = 和 cookie 值。

\\b((?!cookieToKeep1=\[^;\]*|cookieToKeep2=\[^;\]*).)\\S+

我尝试过的 Apache 指令:

RequestHeader edit Cookie "(\b((?!cookieToKeep1=[^;]*|cookieToKeep2=[^;]*).)\S+)" ""

Trying to modify an apache request header directive, I need to use a negative lookahead regex to keep only certain cookies.

Test string

someCookie=someValue; anotherCookie=yada61; cookieToKeep1=myValue; cookieToKeep2=myValue2; lastCookie=yada1

Trying to remove all cookies but cookieToKeep1 and cookieToKeep2.

I can use the below regex but only matches the name and not the = and cookie value.

\\b((?!cookieToKeep1=\[^;\]*|cookieToKeep2=\[^;\]*).)\\S+

Apache directive that I tried:

RequestHeader edit Cookie "(\b((?!cookieToKeep1=[^;]*|cookieToKeep2=[^;]*).)\S+)" ""

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

孤者何惧 2025-01-26 14:39:39

您可以使用此指令删除除cockietokeep1cookietokeep2

RequestHeader edit* Cookie "\b(?!(?:cookieToKeep1|cookieToKeep2)=)([^;=]+=[^;]*(?:; *|$))" ""

requestheader编辑*执行多个搜索和替换。

REGEX DEMO

You can use this directive to remove all cookies except cookieToKeep1 and cookieToKeep2:

RequestHeader edit* Cookie "\b(?!(?:cookieToKeep1|cookieToKeep2)=)([^;=]+=[^;]*(?:; *|$))" ""

RequestHeader edit* performs multiple search and replacements.

RegEx Demo

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文