JS Regular Expressions convert URLs to JSON format

Source: Internet
Author: User

Use Replace to convert the address bar:

varUrl= ' https://www.baidu.com/s?ie=utf-8&f=8&rsv_bp=1&rsv_idx=1&tn=baidu&wd=js%E6%AD%A3%E5%88 %99%e8%a1%a8%e8%be%be%e5%bc%8f&oq=js%e6%ad%a3%e5%88%99%e8%a1%a8%e8%be%be%e5%bc%8f%20kongge&rsv_pq= E63baa94000c303c&rsv_t=2200eomme0fgnsjlppijbdy2ww1cakuxvt8jce2bif1gxlj%2btzixfz%2batle&rsv_enter=1 &inputt=294&rsv_sug3=56&rsv_sug1=15&rsv_sug7=100&rsv_sug2=0&rsv_sug4=772&rsv_sug=2 ‘;//parsing the simulated address bar//var url = location.search.substr (1); This is the case of intercepting the address bar, "? "Question mark after the contentvarparam ={};url.replace (/([^?&]+) = ([^?&]+)/g,function(S, V, K) {Console.log (' This is the chosen a=b: ' +s+ ', \ n This is the key: ' +v+ ', \ n This is the value: ' +k+ '. ‘); PARAM[V]= decodeURIComponent (k);//parse character to Chinese    returnK + ' = ' +v;}); Console.log (param);/*The output is: *f: "8" *ie: "Utf-8" *inputt: "294" *oq: "JS regular expression Kongge" *RSV_BP: "1" *rsv_enter: "1" *RSV_IDX: "1" *RSV_PQ: " e63baa94000c303c "*rsv_sug:" 2 "*RSV_SUG1:" The "*RSV_SUG2:" 0 "*rsv_sug3:" "" *rsv_sug4 "772:" [] ":" *rsv_sug7 ":" 2200eomme0fgnsjlppijbdy2ww1cakuxvt8jce2bif1gxlj+tzixfz+atle "*TN:" Baidu "*WD:" JS Regular expression "*/

JS Regular Expressions convert URLs to JSON format

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.