replace in javascript to cut off part of string











up vote
0
down vote

favorite












I have this string, how can I make it until .html?



string



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1


make it into



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html









share|improve this question




















  • 4




    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.
    – CertainPerformance
    Nov 20 at 7:15










  • @CertainPerformance but I have no clue how to start?
    – Micheal
    Nov 20 at 7:16










  • Check How do I parse a URL into hostname and path in javascript?
    – Mohammad
    Nov 20 at 7:22






  • 1




    Michael, it is not appropriate to suddenly change the scope of your question. Now all of those answers are invalid.
    – KarelG
    Nov 20 at 7:31










  • @KarelG ok then.
    – Micheal
    Nov 20 at 7:39















up vote
0
down vote

favorite












I have this string, how can I make it until .html?



string



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1


make it into



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html









share|improve this question




















  • 4




    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.
    – CertainPerformance
    Nov 20 at 7:15










  • @CertainPerformance but I have no clue how to start?
    – Micheal
    Nov 20 at 7:16










  • Check How do I parse a URL into hostname and path in javascript?
    – Mohammad
    Nov 20 at 7:22






  • 1




    Michael, it is not appropriate to suddenly change the scope of your question. Now all of those answers are invalid.
    – KarelG
    Nov 20 at 7:31










  • @KarelG ok then.
    – Micheal
    Nov 20 at 7:39













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I have this string, how can I make it until .html?



string



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1


make it into



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html









share|improve this question















I have this string, how can I make it until .html?



string



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1


make it into



https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html






javascript ecmascript-6






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 at 7:37









KarelG

3,97632443




3,97632443










asked Nov 20 at 7:15









Micheal

213




213








  • 4




    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.
    – CertainPerformance
    Nov 20 at 7:15










  • @CertainPerformance but I have no clue how to start?
    – Micheal
    Nov 20 at 7:16










  • Check How do I parse a URL into hostname and path in javascript?
    – Mohammad
    Nov 20 at 7:22






  • 1




    Michael, it is not appropriate to suddenly change the scope of your question. Now all of those answers are invalid.
    – KarelG
    Nov 20 at 7:31










  • @KarelG ok then.
    – Micheal
    Nov 20 at 7:39














  • 4




    The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.
    – CertainPerformance
    Nov 20 at 7:15










  • @CertainPerformance but I have no clue how to start?
    – Micheal
    Nov 20 at 7:16










  • Check How do I parse a URL into hostname and path in javascript?
    – Mohammad
    Nov 20 at 7:22






  • 1




    Michael, it is not appropriate to suddenly change the scope of your question. Now all of those answers are invalid.
    – KarelG
    Nov 20 at 7:31










  • @KarelG ok then.
    – Micheal
    Nov 20 at 7:39








4




4




The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.
– CertainPerformance
Nov 20 at 7:15




The posted question does not appear to include any attempt at all to solve the problem. StackOverflow expects you to try to solve your own problem first, as your attempts help us to better understand what you want. Please edit the question to show what you've tried, so as to illustrate a specific roadblock you're running into a Minimal, Complete, and Verifiable example. For more information, please see How to Ask and take the tour.
– CertainPerformance
Nov 20 at 7:15












@CertainPerformance but I have no clue how to start?
– Micheal
Nov 20 at 7:16




@CertainPerformance but I have no clue how to start?
– Micheal
Nov 20 at 7:16












Check How do I parse a URL into hostname and path in javascript?
– Mohammad
Nov 20 at 7:22




Check How do I parse a URL into hostname and path in javascript?
– Mohammad
Nov 20 at 7:22




1




1




Michael, it is not appropriate to suddenly change the scope of your question. Now all of those answers are invalid.
– KarelG
Nov 20 at 7:31




Michael, it is not appropriate to suddenly change the scope of your question. Now all of those answers are invalid.
– KarelG
Nov 20 at 7:31












@KarelG ok then.
– Micheal
Nov 20 at 7:39




@KarelG ok then.
– Micheal
Nov 20 at 7:39












4 Answers
4






active

oldest

votes

















up vote
3
down vote



accepted










Maybe you're looking for something like this example:






var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

console.log(str.match('^.+.html')[0]);





I've used regex with the pattern ^.+.html to match the url. The regex means: From the beginning of the string to .html





If you want to split the url to 2 parts, you could try:






var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

var parts = str.split(/?/);

console.log(parts[0]);
console.log('?' + parts[1]);








share|improve this answer























  • There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
    – KarelG
    Nov 20 at 7:26












  • what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
    – Micheal
    Nov 20 at 7:29


















up vote
1
down vote













You can use String.prototype.split()






var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


console.log(url.split('?', 1)[0])








share|improve this answer




























    up vote
    0
    down vote













    You can use the URL API:



    var url = new URL(string);
    url.search = "";
    url.hash = "";
    return url.href;





    share|improve this answer





















    • nice but what is the next step? I want to replace the cleaned url back into its location.
      – Micheal
      Nov 20 at 7:30










    • @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
      – Bergi
      Nov 20 at 7:32










    • sorry updated my question just now. It's not only the string, the urls are within a document string.
      – Micheal
      Nov 20 at 7:38




















    up vote
    0
    down vote













    This works fine according to your requirment



    let url = "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable- 
    battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1"


    url.substring(0, <nbsp> url.indexOf('.html')<nbsp> + <nbsp>5)





    share|improve this answer























      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387991%2freplace-in-javascript-to-cut-off-part-of-string%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      3
      down vote



      accepted










      Maybe you're looking for something like this example:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      console.log(str.match('^.+.html')[0]);





      I've used regex with the pattern ^.+.html to match the url. The regex means: From the beginning of the string to .html





      If you want to split the url to 2 parts, you could try:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      var parts = str.split(/?/);

      console.log(parts[0]);
      console.log('?' + parts[1]);








      share|improve this answer























      • There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
        – KarelG
        Nov 20 at 7:26












      • what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
        – Micheal
        Nov 20 at 7:29















      up vote
      3
      down vote



      accepted










      Maybe you're looking for something like this example:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      console.log(str.match('^.+.html')[0]);





      I've used regex with the pattern ^.+.html to match the url. The regex means: From the beginning of the string to .html





      If you want to split the url to 2 parts, you could try:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      var parts = str.split(/?/);

      console.log(parts[0]);
      console.log('?' + parts[1]);








      share|improve this answer























      • There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
        – KarelG
        Nov 20 at 7:26












      • what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
        – Micheal
        Nov 20 at 7:29













      up vote
      3
      down vote



      accepted







      up vote
      3
      down vote



      accepted






      Maybe you're looking for something like this example:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      console.log(str.match('^.+.html')[0]);





      I've used regex with the pattern ^.+.html to match the url. The regex means: From the beginning of the string to .html





      If you want to split the url to 2 parts, you could try:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      var parts = str.split(/?/);

      console.log(parts[0]);
      console.log('?' + parts[1]);








      share|improve this answer














      Maybe you're looking for something like this example:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      console.log(str.match('^.+.html')[0]);





      I've used regex with the pattern ^.+.html to match the url. The regex means: From the beginning of the string to .html





      If you want to split the url to 2 parts, you could try:






      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      var parts = str.split(/?/);

      console.log(parts[0]);
      console.log('?' + parts[1]);








      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      console.log(str.match('^.+.html')[0]);





      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      console.log(str.match('^.+.html')[0]);





      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      var parts = str.split(/?/);

      console.log(parts[0]);
      console.log('?' + parts[1]);





      var str = 'https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1';

      var parts = str.split(/?/);

      console.log(parts[0]);
      console.log('?' + parts[1]);






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Nov 20 at 7:36

























      answered Nov 20 at 7:19









      Foo

      1




      1












      • There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
        – KarelG
        Nov 20 at 7:26












      • what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
        – Micheal
        Nov 20 at 7:29


















      • There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
        – KarelG
        Nov 20 at 7:26












      • what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
        – Micheal
        Nov 20 at 7:29
















      There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
      – KarelG
      Nov 20 at 7:26






      There is a reason why there is something called as URL API I rather prefer to see users using this instead of that regex route because this answer is not useful if you have to include other extensions as well (eg .php or .asp).
      – KarelG
      Nov 20 at 7:26














      what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
      – Micheal
      Nov 20 at 7:29




      what I have other string around the url? then it should catch the https as prefix, also how do I replace it?, I don't want to print out the url only, I want the entire text.
      – Micheal
      Nov 20 at 7:29












      up vote
      1
      down vote













      You can use String.prototype.split()






      var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


      console.log(url.split('?', 1)[0])








      share|improve this answer

























        up vote
        1
        down vote













        You can use String.prototype.split()






        var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


        console.log(url.split('?', 1)[0])








        share|improve this answer























          up vote
          1
          down vote










          up vote
          1
          down vote









          You can use String.prototype.split()






          var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


          console.log(url.split('?', 1)[0])








          share|improve this answer












          You can use String.prototype.split()






          var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


          console.log(url.split('?', 1)[0])








          var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


          console.log(url.split('?', 1)[0])





          var url =  "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable-battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1";


          console.log(url.split('?', 1)[0])






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 20 at 7:26









          Gildas.Tambo

          16.3k33663




          16.3k33663






















              up vote
              0
              down vote













              You can use the URL API:



              var url = new URL(string);
              url.search = "";
              url.hash = "";
              return url.href;





              share|improve this answer





















              • nice but what is the next step? I want to replace the cleaned url back into its location.
                – Micheal
                Nov 20 at 7:30










              • @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
                – Bergi
                Nov 20 at 7:32










              • sorry updated my question just now. It's not only the string, the urls are within a document string.
                – Micheal
                Nov 20 at 7:38

















              up vote
              0
              down vote













              You can use the URL API:



              var url = new URL(string);
              url.search = "";
              url.hash = "";
              return url.href;





              share|improve this answer





















              • nice but what is the next step? I want to replace the cleaned url back into its location.
                – Micheal
                Nov 20 at 7:30










              • @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
                – Bergi
                Nov 20 at 7:32










              • sorry updated my question just now. It's not only the string, the urls are within a document string.
                – Micheal
                Nov 20 at 7:38















              up vote
              0
              down vote










              up vote
              0
              down vote









              You can use the URL API:



              var url = new URL(string);
              url.search = "";
              url.hash = "";
              return url.href;





              share|improve this answer












              You can use the URL API:



              var url = new URL(string);
              url.search = "";
              url.hash = "";
              return url.href;






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Nov 20 at 7:24









              Bergi

              360k56535855




              360k56535855












              • nice but what is the next step? I want to replace the cleaned url back into its location.
                – Micheal
                Nov 20 at 7:30










              • @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
                – Bergi
                Nov 20 at 7:32










              • sorry updated my question just now. It's not only the string, the urls are within a document string.
                – Micheal
                Nov 20 at 7:38




















              • nice but what is the next step? I want to replace the cleaned url back into its location.
                – Micheal
                Nov 20 at 7:30










              • @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
                – Bergi
                Nov 20 at 7:32










              • sorry updated my question just now. It's not only the string, the urls are within a document string.
                – Micheal
                Nov 20 at 7:38


















              nice but what is the next step? I want to replace the cleaned url back into its location.
              – Micheal
              Nov 20 at 7:30




              nice but what is the next step? I want to replace the cleaned url back into its location.
              – Micheal
              Nov 20 at 7:30












              @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
              – Bergi
              Nov 20 at 7:32




              @Micheal What do you mean by "its location"? You had a string for the url, right? Now you have the new url string.
              – Bergi
              Nov 20 at 7:32












              sorry updated my question just now. It's not only the string, the urls are within a document string.
              – Micheal
              Nov 20 at 7:38






              sorry updated my question just now. It's not only the string, the urls are within a document string.
              – Micheal
              Nov 20 at 7:38












              up vote
              0
              down vote













              This works fine according to your requirment



              let url = "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable- 
              battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1"


              url.substring(0, <nbsp> url.indexOf('.html')<nbsp> + <nbsp>5)





              share|improve this answer



























                up vote
                0
                down vote













                This works fine according to your requirment



                let url = "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable- 
                battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1"


                url.substring(0, <nbsp> url.indexOf('.html')<nbsp> + <nbsp>5)





                share|improve this answer

























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  This works fine according to your requirment



                  let url = "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable- 
                  battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1"


                  url.substring(0, <nbsp> url.indexOf('.html')<nbsp> + <nbsp>5)





                  share|improve this answer














                  This works fine according to your requirment



                  let url = "https://www.lazada.com.ph/products/fujitsu-standard-aa-rechargeable- 
                  battery-2000mah-4pcs-i237968048-s311807989.html?spm=a2o4k.searchlist.list.47.7f1a484d4gpCFd&search=1"


                  url.substring(0, <nbsp> url.indexOf('.html')<nbsp> + <nbsp>5)






                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 20 at 7:37









                  chŝdk

                  23.2k52852




                  23.2k52852










                  answered Nov 20 at 7:29









                  this is yash

                  767




                  767






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53387991%2freplace-in-javascript-to-cut-off-part-of-string%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      404 Error Contact Form 7 ajax form submitting

                      How to know if a Active Directory user can login interactively

                      Refactoring coordinates for Minecraft Pi buildings written in Python