How to remove the spaces at both ends of the data of each column (tab split) (the data has its own spaces and is not deleted)

problem description
I have a set of data here, which is split with tab keys in textarea

< textarea onblur = "takeout (this)" > ID Log2FoldChange Padj Label
ENSG00000152583-4.61 1.33E-101 SPARCL1
ENSG00000148175-1.43 1.43E-57-
ENSG00000179094-3.18 5.72E-53 PER1
ENSG00000134686-1.39 3.02E-48-
ENSG00000125148-2.20 1.94E-46-
ENSG00000120129-2.95 4.73E-46-
ENSG00000139132-2.26 1.56E- 25-
ENSG00000181467 1.298.07E-25-< / textarea >
the background of the problem and what methods you have tried

    
                    <script>
                        function takeout(th) {
                            var text2 = $("textarea").val();
                            var allcon2 = text2.split("\n");
                            var str = "";
                            for (var i = 0; i < allcon2.length; iPP) {
                                str += allcon2[i].replace(/(^\s*)|(\s*$)/g, "") + "\n"
                            }
                            $(th).val(str.replace(/(^\s*)|(\s*$)/g, ""))
                            return true;
                        }
                    </script>

now I want to remove the spaces at both ends of each column. How can I change it? there is no way of thinking or removing the spaces at both ends of each data (the spaces in the data are reserved). (the event is to point out that onblur executes takeout (this)) instructions: all spaces in value cannot be removed directly, because there may be normal spaces in the value. It is possible to have one or more delimiters except the tab key, that is, delete all the delimiters that come with the data and do not delete them. Do you have any good methods to put them back into the original textarea after removal? it is best to use jquery ~ ~ Thank you

Dec.09,2021
When
`
      ID Log2FoldChange Padj Label    
      ENSG00000152583 -4.61 1.33E-101 SPARCL1    
      ENSG00000148175 -1.43 1.43E-57 -    
      ENSG00000179094 -3.18 5.72E-53 PER1    
      ENSG00000134686 -1.39 3.02E-48 -    
      ENSG00000125148 -2.20 1.94E-46 -    
      ENSG00000120129 -2.95 4.73E-46 -    
      ENSG00000139132 -2.26 1.56E-25 -    
      ENSG00000181467 1.29 8.07E-25 -    
`.match(/.+/g).map(cur => cur.trim()).join('\n');

regular expression matches, there is a multi-line matching pattern m that performs multi-line matching. , take a look at https://developer.mozilla.org.

Menu