日期:2014-05-17  浏览次数:20774 次

问个正则
HTML code

<%
dim str
str = "Cache-Control: no-store, no-cache, must-revalidate,post-check=0, pre-check=0,private
Pragma: no-cache
Content-Length: 32609
Content-Type: text/html
Expires: Sat, 18 Jan 1997 18:36:16 GMT
Set-Cookie: bhCookieSaveSess=1; path=/
Set-Cookie: bhCookieSess=1; path=/
X-XSS-Protection: 0
Date: Sun, 15 Apr 2012 12:54:21 GMT
Set-Cookie: TSac8f66=cf69bf0e0f7faebafba0edada47b6bd4b0e5d8818c9eed6f4f8ac4fd; Path=/"
' str 是一个http响应头,内含有很多回车
%>



我怎么写正则,最后得到的结果是

result = "hCookieSaveSess=1; bhCookieSess=1; TSac8f66=cf69bf0e0f7faebafba0edada47b6bd4b0e5d8818c9eed6f4f8ac4fd; Path=/"

即,把所有的 Set-Cookie 的值合并,并丢弃重复的部分

------解决方案--------------------
用正则
(?<=Set-Cookie: ).*?;//得到hCookieSaveSess=1;bhCookieSess=1; TSac8f66=cf69bf0e0f7faebafba0edada47b6bd4b0e5d8818c9eed6f4f8ac4fd;
在拼接就是了
------解决方案--------------------
var reg=/Set-Cookie:.*/gi;
ps:
js正则不支持 (?<=)
------解决方案--------------------
探讨

var reg=/Set-Cookie:.*/gi;
ps:
js正则不支持 (?<=)

------解决方案--------------------
JScript code

<script language="JavaScript">
var str = 'Cache-Control: no-store, no-cache, must-revalidate,post-check=0, pre-check=0,private\r\nPragma: no-cache\r\nContent-Length: 32609\r\nContent-Type: text/html\r\nExpires: Sat, 18 Jan \r\n997 18:36:16 GMT\r\nSet-Cookie: bhCookieSaveSess=1; path=/\r\nSet-Cookie: bhCookieSess=1; path=/\r\nX-XSS-Protection: 0\r\nDate: Sun, 15 Apr 2012 12:54:21 GMT\r\nSet-Cookie: TSac8f66=cf69bf0e0f7faebafba0edada47b6bd4b0e5d8818c9eed6f4f8ac4fd; Path=/';
var reg = /Set-Cookie:\s?(.+?)path=\//gi;
var r = '';
str.replace(reg, function($){
    reg.exec(str);
    r += RegExp.$1;
})
r += 'Path=/';
alert(r);
</script>

------解决方案--------------------
Set-Cookie:.+/s/Spath=
------解决方案--------------------
探讨

换个问法吧,把除了Set-Cookie: ....; path=/以外的其他行都删除,正则怎么写?

str.replace(这里的正则怎么写?,'')

------解决方案--------------------
探讨

引用:

换个问法吧,把除了Set-Cookie: ....; path=/以外的其他行都删除,正则怎么写?

str.replace(这里的正则怎么写?,'')

这可不可以理解成 除了提取 Set-Cookie: ....; path=/以外
其他什么都不提取?

------解决方案--------------------
http://baike.baidu.com/view/94238.htm#4