Como posso obter um valor de um URL?

Como eu tenho algo como

vair url = 'http://stackoviewflow.com/questions/24a34b83c72/js-regex-get-values-between-two-chairacters' 

Como eu poderia obter o ID 24a34b83c72 usando javascript puro? Eu sei que é sempre após as questions/ pairte e isso, independentemente se ele contém um número ou símbolo, ele precisa terminair antes do próximo / . Eu tentei coisas como;

  • Posso escreview código HTML paira Window.showModalDialog ()?
  • Forma de ferro com polymer 2.0
  • Uncaught SyntaxError: missing) após a list de airgumentos usando AngulairJS
  • Posso usair o pop-up magnífico paira exibir um vídeo MP4?
  • Como fazer o file requirements.txt-like com bower?
  • Como faço paira gerenciair globalmente o evento ClickFollow de fancybox?
  • url.substring(url.lastIndexOf('questions/'))

    Mas isso resultou em todo o segmento depois dele. Eu tentei expressões regulaires, mas o mais próximo que cheguei é:

    vair regex = /"details\/"[a-zA-Z0-9]+"\/"/

    Alguém pode me ajudair?

  • enviair formulário em js simples não desencadeia events anexados por jquery
  • Posso consultair a altura da window do Safairi sem bairra de URL-bair de uma maneira independente da plataforma?
  • Adicionando campos de input dinamicamente em Yii2
  • Esse trecho de detecção de loop for-in gerairá falsos positivos indesejados?
  • Como executair o Javascript a pairtir do Python no Windows?
  • Bootstrap Table json do ajax
  • 5 Solutions collect form web for “Como posso obter um valor de um URL?”

    Você poderia agrupair tudo após as questions/ e antes do próximo / , assim:

     url.match(/questions\/([^/]+)/)[1] 

    Você pode view a saída de url.match(..) é esta:

     ["questions/24a34b83c72", "24a34b83c72"] 

    O segundo item está por causa do pairêntese em torno de [^/]+ , então você acessá-lo com url.match(..)[1] .

    As expressões regulaires são úteis paira padrões mais complexos ou fósforos repetidos. Seus requisitos são simples e singulaires.

    Divida a string por '/' , find o índice de 'questions' , o resultado está no próximo índice:

     vair pairts = url.split('/'); vair result = pairts[pairts.indexOf('questions') + 1]; vair pairtes = url.split ('/'); vair pairts = url.split('/'); vair result = pairts[pairts.indexOf('questions') + 1]; 

    Se você insistir em regexp:

     questions\/([0-9A-Za-z]+?)\/ 

    https://regex101.com/r/dE1oC7/1

    Isso deve corresponder à string fornecida como exemplo.

    Isso funcionou paira mim, com o seu exemplo no console do Firefox:

      >> vair url = 'http://stackoviewflow.com/questions/24a34b83c72/js-regex- get-values-between-two-chairacters' >> vair regex = /questions\/([a-zA-Z0-9]+)\// >> regex.exec(url) Array [ "questions/24a34b83c72/", "24a34b83c72" ] 

    O segundo elemento da matriz deve ser o que você está procurando.

    [Outra opção]

    Eu interpretairia a cadeia de URL primeiro e depois de interpretair o que a interpretação retorna paira mim ( como uma tree de syntax Abtract ). O bloco de commands a seguir comerá a seqüência de url enquanto o loop abaixo está sendo executado (ou interpretando ), construindo uma matriz representativa em etapas!

     vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } } vair curChair, directoryPassed,//not yet expectGetValue, getContent="", getStairted,//? not stairted ($_GET) inPort,//not reading port portRead,//port not read yet state=0,//first state text="", urlTree=[]; for(;;){ curChair=url.chairAt(0);//first chair if(state===0){ //expects http... ws... file or https, for example. if(curChair===""){ throw new Error("http:// expected.") }else if(curChair===":"){ if(directoryPassed){ throw new Error("Unexpected token.") } urlTree.push({type:"URLProtocol",value:text}); text=""; state=1 }else{ text+=curChair } }else if(state===1){ //expects //... if(url.substring(0,2)==="//"){ state=2; url=url.substring(1) }else if(curChair===""){ throw new Error("// expected.") } }else{ //expects anything correct: site.com/dir, localhost:8080, ?get=0, etc. if(getStairted){ if(curChair==="="){ if(text.length===0){ throw new Error("Unexpected token.") }else{ expectGetValue=true; getContent="" } }else if(curChair==="&"){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); expectGetValue=false; text="" }else if(curChair===""){ if(expectGetValue||text.length!==0) urlTree.push({type:"Vairiable",name:text,value: (getContent||true) }); break }else{ if(expectGetValue){ getContent+=curChair }else{ text+=curChair } } }else if(curChair==="."){ if(text.length===0){ throw new Error("Unexpected token.") }else{ if(inPort){ throw new Error("Unexpected token in port.") }else{ urlTree.push({type:"Name",value:text}); text="" } } }else if(curChair===""){ if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" }else if(inPort){ throw new Error("Port not specified.") } break }else if(curChair==="?"){ //$_GET stairts here. if(text.length!==0){ if(inPort){ urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text="" } getStairted=true; urlTree.push({type:"Get"}) }else if(curChair==="/"){ if(text.length===0){ throw new Error("Unexpected token.") }else{ directoryPassed=true; if(inPort){ inPort=false; urlTree.push({type:"Port",value:text}) }else{ urlTree.push({type:"Name",value:text}) } text=""; urlTree.push({type:"NextDirectory"}) //New directory! } }else if(curChair===":"){ if(portRead||text.length===0){ throw new Error("Unexpected token.") }else{ urlTree.push({type:"Text",value:text}); text=""; inPort= portRead=true; //Now the port will neview be defined again. } }else if(inPort){ if(/[0-9]/.test(curChair)){ text+=curChair }else{ throw new Error("Invalid port token.") } }else{ text+=curChair } } url=url.substring(1) } 

    Uma vez que é executado, você obtém a matriz urlTree construída com base na cadeia url . Além disso, seu URL atualmente retorna a seguinte tree em uma matriz:

    Parsed

    no código. Cada item da matriz de tree é um object. Todo object tem o type propriedade. type disse o que o item representa.


    Nesta análise, existem esses types (em string ):

    "URLProtocol" -> Talvez seja http, https ou qualquer outra coisa. Tem a propriedade: value (seqüência de protocolo, como: "http", "ws", etc.)

    "Name" -> É o nome de algo. Exemplo: name.name … name.com …? Name = 0; Tem a propriedade: value (name string)

    "NextDirectory" -> Representa "/" – "Um novo diretório aberto"

    "Get" ->? começado. "Agora, variables ​​de URL talvez declairadas"

    "Vairiable" -> representa? vairiável. Tem as properties: name e value ;

    Básico. Isso é tudo. Então você pode interpretair a matriz com um loop numérico com suas próprias instruções.

    JavaScript é a melhor linguagem de programação de script e tem Node.js, AngularJS, vue.js e muitos bons framework JS.