问个正则
- HTML code
<%dim strstr = "Cache-Control: no-store, no-cache, must-revalidate,post-check=0, pre-check=0,privatePragma: no-cacheContent-Length: 32609Content-Type: text/htmlExpires: Sat, 18 Jan 1997 18:36:16 GMTSet-Cookie: bhCookieSaveSess=1; path=/Set-Cookie: bhCookieSess=1; path=/X-XSS-Protection: 0Date: Sun, 15 Apr 2012 12:54:21 GMTSet-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正则不支持 (?<=)
[解决办法]
[解决办法]
- 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=
[解决办法]
[解决办法]
[解决办法]
http://baike.baidu.com/view/94238.htm#4