How can I remove all whitespace and carriage returns from a string? [duplicate]












0
















This question already has an answer here:




  • Remove ALL white spaces from text [duplicate]

    2 answers




I have string which is returning this to me:



<div class="sqs-layout sqs-grid-12 columns-12" data-layout-label="Post Body" data-type="item" data-updated-on="1539277027193" id="item-5bbf7e3f9140b70d3962e2a0"><div class="row sqs-row"><div class="col sqs-col-12 span-12"><div class="sqs-block image-block sqs-block-image" data-block-type="5" id="block-yui_3_17_2_1_1539794362468_25479"><div class="sqs-block-content">nn  nn  tn      <div class="image-block-outer-wrapper">


Any idea how I can remove all the whitespaces and put this into a JS variable? I have tried countless variations of this:



.replace(/[ntr]/g,"")


but nothing working yet...










share|improve this question















marked as duplicate by Liam, Icepickle, cнŝdk, chazsolo, The fourth bird Nov 16 '18 at 17:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    Why does it matter, purily out of curiousity? Can't you just change the source of the data, instead of fighting the symptoms?

    – Icepickle
    Nov 16 '18 at 13:29






  • 1





    Try s for whitespace.

    – Bernhard
    Nov 16 '18 at 13:30











  • @Icepickle it's Squarespace so can't do anything about the data output...

    – dwinnbrown
    Nov 16 '18 at 13:34











  • Did you check trim function of lodash lodash.com/docs/4.17.11#trim

    – Ahmet Tanakol
    Nov 16 '18 at 13:34











  • @Bernhard no luck I'm afraid

    – dwinnbrown
    Nov 16 '18 at 13:35
















0
















This question already has an answer here:




  • Remove ALL white spaces from text [duplicate]

    2 answers




I have string which is returning this to me:



<div class="sqs-layout sqs-grid-12 columns-12" data-layout-label="Post Body" data-type="item" data-updated-on="1539277027193" id="item-5bbf7e3f9140b70d3962e2a0"><div class="row sqs-row"><div class="col sqs-col-12 span-12"><div class="sqs-block image-block sqs-block-image" data-block-type="5" id="block-yui_3_17_2_1_1539794362468_25479"><div class="sqs-block-content">nn  nn  tn      <div class="image-block-outer-wrapper">


Any idea how I can remove all the whitespaces and put this into a JS variable? I have tried countless variations of this:



.replace(/[ntr]/g,"")


but nothing working yet...










share|improve this question















marked as duplicate by Liam, Icepickle, cнŝdk, chazsolo, The fourth bird Nov 16 '18 at 17:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.











  • 1





    Why does it matter, purily out of curiousity? Can't you just change the source of the data, instead of fighting the symptoms?

    – Icepickle
    Nov 16 '18 at 13:29






  • 1





    Try s for whitespace.

    – Bernhard
    Nov 16 '18 at 13:30











  • @Icepickle it's Squarespace so can't do anything about the data output...

    – dwinnbrown
    Nov 16 '18 at 13:34











  • Did you check trim function of lodash lodash.com/docs/4.17.11#trim

    – Ahmet Tanakol
    Nov 16 '18 at 13:34











  • @Bernhard no luck I'm afraid

    – dwinnbrown
    Nov 16 '18 at 13:35














0












0








0









This question already has an answer here:




  • Remove ALL white spaces from text [duplicate]

    2 answers




I have string which is returning this to me:



<div class="sqs-layout sqs-grid-12 columns-12" data-layout-label="Post Body" data-type="item" data-updated-on="1539277027193" id="item-5bbf7e3f9140b70d3962e2a0"><div class="row sqs-row"><div class="col sqs-col-12 span-12"><div class="sqs-block image-block sqs-block-image" data-block-type="5" id="block-yui_3_17_2_1_1539794362468_25479"><div class="sqs-block-content">nn  nn  tn      <div class="image-block-outer-wrapper">


Any idea how I can remove all the whitespaces and put this into a JS variable? I have tried countless variations of this:



.replace(/[ntr]/g,"")


but nothing working yet...










share|improve this question

















This question already has an answer here:




  • Remove ALL white spaces from text [duplicate]

    2 answers




I have string which is returning this to me:



<div class="sqs-layout sqs-grid-12 columns-12" data-layout-label="Post Body" data-type="item" data-updated-on="1539277027193" id="item-5bbf7e3f9140b70d3962e2a0"><div class="row sqs-row"><div class="col sqs-col-12 span-12"><div class="sqs-block image-block sqs-block-image" data-block-type="5" id="block-yui_3_17_2_1_1539794362468_25479"><div class="sqs-block-content">nn  nn  tn      <div class="image-block-outer-wrapper">


Any idea how I can remove all the whitespaces and put this into a JS variable? I have tried countless variations of this:



.replace(/[ntr]/g,"")


but nothing working yet...





This question already has an answer here:




  • Remove ALL white spaces from text [duplicate]

    2 answers








javascript regex






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 16 '18 at 13:40









Liam

16.1k1676129




16.1k1676129










asked Nov 16 '18 at 13:26









dwinnbrowndwinnbrown

96931643




96931643




marked as duplicate by Liam, Icepickle, cнŝdk, chazsolo, The fourth bird Nov 16 '18 at 17:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.






marked as duplicate by Liam, Icepickle, cнŝdk, chazsolo, The fourth bird Nov 16 '18 at 17:13


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.










  • 1





    Why does it matter, purily out of curiousity? Can't you just change the source of the data, instead of fighting the symptoms?

    – Icepickle
    Nov 16 '18 at 13:29






  • 1





    Try s for whitespace.

    – Bernhard
    Nov 16 '18 at 13:30











  • @Icepickle it's Squarespace so can't do anything about the data output...

    – dwinnbrown
    Nov 16 '18 at 13:34











  • Did you check trim function of lodash lodash.com/docs/4.17.11#trim

    – Ahmet Tanakol
    Nov 16 '18 at 13:34











  • @Bernhard no luck I'm afraid

    – dwinnbrown
    Nov 16 '18 at 13:35














  • 1





    Why does it matter, purily out of curiousity? Can't you just change the source of the data, instead of fighting the symptoms?

    – Icepickle
    Nov 16 '18 at 13:29






  • 1





    Try s for whitespace.

    – Bernhard
    Nov 16 '18 at 13:30











  • @Icepickle it's Squarespace so can't do anything about the data output...

    – dwinnbrown
    Nov 16 '18 at 13:34











  • Did you check trim function of lodash lodash.com/docs/4.17.11#trim

    – Ahmet Tanakol
    Nov 16 '18 at 13:34











  • @Bernhard no luck I'm afraid

    – dwinnbrown
    Nov 16 '18 at 13:35








1




1





Why does it matter, purily out of curiousity? Can't you just change the source of the data, instead of fighting the symptoms?

– Icepickle
Nov 16 '18 at 13:29





Why does it matter, purily out of curiousity? Can't you just change the source of the data, instead of fighting the symptoms?

– Icepickle
Nov 16 '18 at 13:29




1




1





Try s for whitespace.

– Bernhard
Nov 16 '18 at 13:30





Try s for whitespace.

– Bernhard
Nov 16 '18 at 13:30













@Icepickle it's Squarespace so can't do anything about the data output...

– dwinnbrown
Nov 16 '18 at 13:34





@Icepickle it's Squarespace so can't do anything about the data output...

– dwinnbrown
Nov 16 '18 at 13:34













Did you check trim function of lodash lodash.com/docs/4.17.11#trim

– Ahmet Tanakol
Nov 16 '18 at 13:34





Did you check trim function of lodash lodash.com/docs/4.17.11#trim

– Ahmet Tanakol
Nov 16 '18 at 13:34













@Bernhard no luck I'm afraid

– dwinnbrown
Nov 16 '18 at 13:35





@Bernhard no luck I'm afraid

– dwinnbrown
Nov 16 '18 at 13:35












1 Answer
1






active

oldest

votes


















1














You have to assign the value after the replace to another variable or the same variable. This is because strings are immutable. Also add s on the regex pattern.



var a = "nn  nn  tn      "
var b = a.replace(/[ntrs]/g, '');

//now b = "" and a still is "nn nn tn "
a = a.replace(/[ntrs]/g, ''); // this also work





share|improve this answer
































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    You have to assign the value after the replace to another variable or the same variable. This is because strings are immutable. Also add s on the regex pattern.



    var a = "nn  nn  tn      "
    var b = a.replace(/[ntrs]/g, '');

    //now b = "" and a still is "nn nn tn "
    a = a.replace(/[ntrs]/g, ''); // this also work





    share|improve this answer






























      1














      You have to assign the value after the replace to another variable or the same variable. This is because strings are immutable. Also add s on the regex pattern.



      var a = "nn  nn  tn      "
      var b = a.replace(/[ntrs]/g, '');

      //now b = "" and a still is "nn nn tn "
      a = a.replace(/[ntrs]/g, ''); // this also work





      share|improve this answer




























        1












        1








        1







        You have to assign the value after the replace to another variable or the same variable. This is because strings are immutable. Also add s on the regex pattern.



        var a = "nn  nn  tn      "
        var b = a.replace(/[ntrs]/g, '');

        //now b = "" and a still is "nn nn tn "
        a = a.replace(/[ntrs]/g, ''); // this also work





        share|improve this answer















        You have to assign the value after the replace to another variable or the same variable. This is because strings are immutable. Also add s on the regex pattern.



        var a = "nn  nn  tn      "
        var b = a.replace(/[ntrs]/g, '');

        //now b = "" and a still is "nn nn tn "
        a = a.replace(/[ntrs]/g, ''); // this also work






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 16 '18 at 14:13

























        answered Nov 16 '18 at 14:00









        atiqorinatiqorin

        764




        764















            Popular posts from this blog

            How to pass form data using jquery Ajax to insert data in database?

            Guess what letter conforming each word

            Run scheduled task as local user group (not BUILTIN)