Regex 从响应头中提取会话ID
如何从这个ResponseHeader中提取JSESSIONID(在“=”之后和“;”之前的所有内容)Regex 从响应头中提取会话ID,regex,Regex,如何从这个ResponseHeader中提取JSESSIONID(在“=”之后和“;”之前的所有内容) Set-Cookie:Apache=40.76.87.14.1462996905538733; path=/; domain=.cra-arc.gc.ca,JSESSIONID=KjahaS5VdMBttn9bAYuS_iHFXOgmqQyMxHcht1kBS7p1YOpdV2V_!1094217526; path=/; HttpOnly 您可以使用以下模式: /JSESSIONID=([^
Set-Cookie:Apache=40.76.87.14.1462996905538733; path=/; domain=.cra-arc.gc.ca,JSESSIONID=KjahaS5VdMBttn9bAYuS_iHFXOgmqQyMxHcht1kBS7p1YOpdV2V_!1094217526; path=/; HttpOnly
您可以使用以下模式:
/JSESSIONID=([^;]*)/
解释上述正则表达式:
JSESSIONID= # match the text literally
( # asserts that all content inside it will be in group $1
[^;] # means any character not ';'
* # as many as possible
) # end of the group $1
您所需的值将位于组1内
您可以在中看到它。您可以使用以下模式:
/JSESSIONID=([^;]*)/
解释上述正则表达式:
JSESSIONID= # match the text literally
( # asserts that all content inside it will be in group $1
[^;] # means any character not ';'
* # as many as possible
) # end of the group $1
您所需的值将位于组1内
您可以在中看到它。您可以使用:
/JSESSIONID=(.*?);/
Regex101演示版:
JSESSIONID=(.*?);
Match the character string “JSESSIONID=” literally (case sensitive) «JSESSIONID=»
Match the regex below and capture its match into backreference number 1 «(.*?)»
Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “;” literally «;»
正则表达式解释:
JSESSIONID=(.*?);
Match the character string “JSESSIONID=” literally (case sensitive) «JSESSIONID=»
Match the regex below and capture its match into backreference number 1 «(.*?)»
Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “;” literally «;»
您可以使用:
/JSESSIONID=(.*?);/
Regex101演示版:
JSESSIONID=(.*?);
Match the character string “JSESSIONID=” literally (case sensitive) «JSESSIONID=»
Match the regex below and capture its match into backreference number 1 «(.*?)»
Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “;” literally «;»
正则表达式解释:
JSESSIONID=(.*?);
Match the character string “JSESSIONID=” literally (case sensitive) «JSESSIONID=»
Match the regex below and capture its match into backreference number 1 «(.*?)»
Match any single character that is NOT a line break character (line feed, carriage return, line separator, paragraph separator) «.*?»
Between zero and unlimited times, as few times as possible, expanding as needed (lazy) «*?»
Match the character “;” literally «;»
谢谢!我想我可以用JS在“=”处拆分字符串,因为它仍然可以捕获整个组,从JSSessionID一直到分号之前的字符串。是的,您可以;)。。。正如您现在所说的是JS,我的答案是:
var result=string.match(/JSESSIONID=([^;]*)/)[1]代码>谢谢!我想我可以用JS在“=”处拆分字符串,因为它仍然捕获整个组,从JSSessionID一直到分号之前的字符串。是的,您可以;)。。。正如您现在所说的是JS,我的答案是:var result=string.match(/JSESSIONID=([^;]*)/)[1]代码>哦,这也很整洁!非常感谢。哦,这也很整洁!非常感谢。