Javascript-Regular Expression greedy mode. How can this problem be clarified? I always matched all of the following at once.

Source: Internet
Author: User
{Code ...} the cookie above matches _ tb_token_obU42Ba54Lp with a regular expression, and uses this expression to directly match the next long string, and then becomes _ tb_token_obU42Ba54Lp; v0; signature; cook...
t=edc9624908fac06b969fc8b3454d4d75; cna=rz39DUM8tSgCAXLjRlx1SJH8; l=Ah8fI61XmUXv5/-aXUJ9Fiy3732phHMm; lzstat_uv=7058553501377199257|1774292@1774054; cookie2=fa6653f49ed68b38b469988a4f1a2ac7; _tb_token_=obU42Ba54Lp; v=0; cookie32=d2874877ef98c1c142fc1ddff656fb50; cookie31=MTA5NzY3MjEsa2lzdGVhcixqc3djQDE2My5jb20sbnVsbA%3D%3D; alimamapwag=TW96aWxsYS80LjAgKGNvbXBhdGlibGU7IE1TSUUgNy4wOyBXaW5kb3dzIE5UIDYuMjsgV09XNjQ7IFRyaWRlbnQvNy4wOyAuTkVUNC4wQzsgLk5FVDQuMEU7IC5ORVQgQ0xSIDIuMC41MDcyNzsgLk5FVCBDTFIgMy4wLjMwNzI5OyAuTkVUIENMUiAzLjUuMzA3Mjkp; login=W5iHLLyFOGW7aA%3D%3D; alimamapw=DggWRANZRTAHBVcABwAEBQRbUFZcAgVeB1oEBwAHU1AEA1INVAUAUg%3D%3D

The cookie above uses regular expression match _ tb_token _ = obU42Ba54Lp; this value,
This expression is used to match the long strings,
Then it turns into _ tb_token _ = obU42Ba54Lp; v = 0; cookie32 = kernel; cookie31 = kernel % 3D % 3D; alimamapwag = kernel; login = W5iHLLyFOGW7aA % 3D % 3D; alimamapw = DggWRANZRTAHBVcABwAEBQRbUFZcAgVeB1oEBwAHU1AEA1INVAUAUg % 3D % 3D
I know it can be done with \ W, but I have to use it. * what should I do? Match to the first ;?

Reply content:
t=edc9624908fac06b969fc8b3454d4d75; cna=rz39DUM8tSgCAXLjRlx1SJH8; l=Ah8fI61XmUXv5/-aXUJ9Fiy3732phHMm; lzstat_uv=7058553501377199257|1774292@1774054; cookie2=fa6653f49ed68b38b469988a4f1a2ac7; _tb_token_=obU42Ba54Lp; v=0; cookie32=d2874877ef98c1c142fc1ddff656fb50; cookie31=MTA5NzY3MjEsa2lzdGVhcixqc3djQDE2My5jb20sbnVsbA%3D%3D; alimamapwag=TW96aWxsYS80LjAgKGNvbXBhdGlibGU7IE1TSUUgNy4wOyBXaW5kb3dzIE5UIDYuMjsgV09XNjQ7IFRyaWRlbnQvNy4wOyAuTkVUNC4wQzsgLk5FVDQuMEU7IC5ORVQgQ0xSIDIuMC41MDcyNzsgLk5FVCBDTFIgMy4wLjMwNzI5OyAuTkVUIENMUiAzLjUuMzA3Mjkp; login=W5iHLLyFOGW7aA%3D%3D; alimamapw=DggWRANZRTAHBVcABwAEBQRbUFZcAgVeB1oEBwAHU1AEA1INVAUAUg%3D%3D

The cookie above uses regular expression match _ tb_token _ = obU42Ba54Lp; this value,
This expression is used to match the long strings,
Then it turns into _ tb_token _ = obU42Ba54Lp; v = 0; cookie32 = kernel; cookie31 = kernel % 3D % 3D; alimamapwag = kernel; login = W5iHLLyFOGW7aA % 3D % 3D; alimamapw = DggWRANZRTAHBVcABwAEBQRbUFZcAgVeB1oEBwAHU1AEA1INVAUAUg % 3D % 3D
I know it can be done with \ W, but I have to use it. * what should I do? Match to the first ;?

1.findall,searchYes. Pay attention to the value returned by the method.
2.patternWrite method, pay attention to matching between greedy and non-greedy
3.HEREDOCIs a good choice, long string time

Import restring = "t = signature; cna = signature; l = Ah8fI61XmUXv5/-aXUJ9Fiy3732phHMm; lzstat_uv = 7058553501377199257 | 1774292 @ 1774054; cookie2 = signature; _ tb_token _ = obU42Ba54Lp; v = 0; cookie32 = d2874877ef98c1c142fc1ddff656fb50; cookie31 = running % 3D % 3D; alimamapwag = tw96awxsys80ljarkgnvbxbhdglibgu7ie1tsuugny Cursor; login = W5iHLLyFOGW7aA % 3D % 3D; alimamapw = %%3d % 3D ""; # Add a list = re when the matching result is not found. findall ("_ tb_token _ = (. *?); ", String, re. S) print (list [0])

out=re.search("_tb_token_=(.*?);",token).groups()[0]print(out)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.