负面的lookahead Regex for Apache Mod cookie-保持某些cookie
尝试修改 apache 请求标头指令,我需要使用负向前看正则表达式来仅保留某些 cookie。
测试字符串
someCookie=someValue; anotherCookie=yada61; cookieToKeep1=myValue; cookieToKeep2=myValue2; lastCookie=yada1
尝试删除除 cookieToKeep1
和 cookieToKeep2
之外的所有 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用此指令删除除
cockietokeep1
和cookietokeep2
:requestheader编辑*
执行多个搜索和替换。REGEX DEMO
You can use this directive to remove all cookies except
cookieToKeep1
andcookieToKeep2
:RequestHeader edit*
performs multiple search and replacements.RegEx Demo