首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > ASP >

问个正则解决办法

2012-04-24 
问个正则HTML code%dim strstr Cache-Control: no-store, no-cache, must-revalidate,post-check0, p

问个正则

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正则不支持 (?<=)
[解决办法]
探讨

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

热点排行