Replace all items that are not belong to characters and numbers by ' 'What is difference between [-a-z] and [a-z] in regular expression?Search and replace strings that are not substrings of other stringssome POSIX Bracket Expressions not workingHow do I keep a part of the pattern matched and use it to replace on BSD sed?find: list all directories except those with numbers in their names and their childrensearch and replace numbers in vimReplace spaces with sed and regexp grouping not workingfind and replace one number with anotherGNU Pattern Match and replace exact number of charactersUsing sed to replace the hexadecimal code for URL and to insert new SVG codes after SVG tag in all SVG filesLinux sed command replace two lines having spaces and special characters using regular expression

how to create an executable file for an AppleScript?

Does the usage of mathematical symbols work differently in books than in theses?

Are there any symmetric cryptosystems based on computational complexity assumptions?

How does this piece of code determine array size without using sizeof( )?

How to pipe results multiple results into a command?

Why does a table with a defined constant in its index compute 10X slower?

Is my company merging branches wrong?

Should I twist DC power and ground wires from a power supply?

French equivalent of the German expression "flöten gehen"

How would fantasy dwarves exist, realistically?

Why would company (decision makers) wait for someone to retire, rather than lay them off, when their role is no longer needed?

How can sister protect herself from impulse purchases with a credit card?

multicol package causes underfull hbox

Prints each letter of a string in different colors. C#

Appropriate liquid/solvent for life in my underground environment on Venus

Is it possible to determine from only a photo of a cityscape whether it was taken close with wide angle or from a distance with zoom?

Shortest amud or daf in Shas?

Why do academics prefer Mac/Linux?

Can an airline pilot be prosecuted for killing an unruly passenger who could not be physically restrained?

Lock out of Oracle based on Windows username

How was the blinking terminal cursor invented?

Error when running ((x++)) as root

How do I balance a campaign consisting of four kobold PCs?

Why use a retrograde orbit?



Replace all items that are not belong to characters and numbers by ' '


What is difference between [-a-z] and [a-z] in regular expression?Search and replace strings that are not substrings of other stringssome POSIX Bracket Expressions not workingHow do I keep a part of the pattern matched and use it to replace on BSD sed?find: list all directories except those with numbers in their names and their childrensearch and replace numbers in vimReplace spaces with sed and regexp grouping not workingfind and replace one number with anotherGNU Pattern Match and replace exact number of charactersUsing sed to replace the hexadecimal code for URL and to insert new SVG codes after SVG tag in all SVG filesLinux sed command replace two lines having spaces and special characters using regular expression






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








2















I want to replace all symbols like '.','-','/' and so on by ' '



I triedsed 's/[[!:alnum:]]/ /g' example.txt but it does not work



and for sed 's/[,;.-/()_]/ /g' example.txt, I found that I cannot replace '-' by ' '.



is there any way to do that?










share|improve this question

















  • 1





    Perhaps the class you are looking for is [[:punct:]]? Regarding the use of - in character brackets, see What is difference between [-a-z] and [a-z] in regular expression?

    – steeldriver
    May 12 at 15:15


















2















I want to replace all symbols like '.','-','/' and so on by ' '



I triedsed 's/[[!:alnum:]]/ /g' example.txt but it does not work



and for sed 's/[,;.-/()_]/ /g' example.txt, I found that I cannot replace '-' by ' '.



is there any way to do that?










share|improve this question

















  • 1





    Perhaps the class you are looking for is [[:punct:]]? Regarding the use of - in character brackets, see What is difference between [-a-z] and [a-z] in regular expression?

    – steeldriver
    May 12 at 15:15














2












2








2








I want to replace all symbols like '.','-','/' and so on by ' '



I triedsed 's/[[!:alnum:]]/ /g' example.txt but it does not work



and for sed 's/[,;.-/()_]/ /g' example.txt, I found that I cannot replace '-' by ' '.



is there any way to do that?










share|improve this question














I want to replace all symbols like '.','-','/' and so on by ' '



I triedsed 's/[[!:alnum:]]/ /g' example.txt but it does not work



and for sed 's/[,;.-/()_]/ /g' example.txt, I found that I cannot replace '-' by ' '.



is there any way to do that?







shell regular-expression






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked May 12 at 15:02









Yiling LiuYiling Liu

304




304







  • 1





    Perhaps the class you are looking for is [[:punct:]]? Regarding the use of - in character brackets, see What is difference between [-a-z] and [a-z] in regular expression?

    – steeldriver
    May 12 at 15:15













  • 1





    Perhaps the class you are looking for is [[:punct:]]? Regarding the use of - in character brackets, see What is difference between [-a-z] and [a-z] in regular expression?

    – steeldriver
    May 12 at 15:15








1




1





Perhaps the class you are looking for is [[:punct:]]? Regarding the use of - in character brackets, see What is difference between [-a-z] and [a-z] in regular expression?

– steeldriver
May 12 at 15:15






Perhaps the class you are looking for is [[:punct:]]? Regarding the use of - in character brackets, see What is difference between [-a-z] and [a-z] in regular expression?

– steeldriver
May 12 at 15:15











1 Answer
1






active

oldest

votes


















5














To match all non-alphanumerics, use [^[:alnum:]]. It's similar to [^abc]: the leading caret makes the bracket expression match all but the listed characters.



To match a literal dash, you need to make sure it's not interpreted as creating a list of characters to match. Make it the first character of the bracket expression: [-,.;/()_].



Note that sed doesn't take the / as a separator for s/// if it's within a bracket expression, so there's no need to put a backslash in front of it. (The backslash will match itself.) E.g. echo 'ab/c' | sed 's/[/]/./g' prints a.b.c.



See for example the regex(7) man page for a description of the regular expression syntax. (Note that it mainly discusses extended regular expressions (ERE), used by sed -E in many/most seds.)






share|improve this answer























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "106"
    ;
    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',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    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%2funix.stackexchange.com%2fquestions%2f518553%2freplace-all-items-that-are-not-belong-to-characters-and-numbers-by%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    To match all non-alphanumerics, use [^[:alnum:]]. It's similar to [^abc]: the leading caret makes the bracket expression match all but the listed characters.



    To match a literal dash, you need to make sure it's not interpreted as creating a list of characters to match. Make it the first character of the bracket expression: [-,.;/()_].



    Note that sed doesn't take the / as a separator for s/// if it's within a bracket expression, so there's no need to put a backslash in front of it. (The backslash will match itself.) E.g. echo 'ab/c' | sed 's/[/]/./g' prints a.b.c.



    See for example the regex(7) man page for a description of the regular expression syntax. (Note that it mainly discusses extended regular expressions (ERE), used by sed -E in many/most seds.)






    share|improve this answer



























      5














      To match all non-alphanumerics, use [^[:alnum:]]. It's similar to [^abc]: the leading caret makes the bracket expression match all but the listed characters.



      To match a literal dash, you need to make sure it's not interpreted as creating a list of characters to match. Make it the first character of the bracket expression: [-,.;/()_].



      Note that sed doesn't take the / as a separator for s/// if it's within a bracket expression, so there's no need to put a backslash in front of it. (The backslash will match itself.) E.g. echo 'ab/c' | sed 's/[/]/./g' prints a.b.c.



      See for example the regex(7) man page for a description of the regular expression syntax. (Note that it mainly discusses extended regular expressions (ERE), used by sed -E in many/most seds.)






      share|improve this answer

























        5












        5








        5







        To match all non-alphanumerics, use [^[:alnum:]]. It's similar to [^abc]: the leading caret makes the bracket expression match all but the listed characters.



        To match a literal dash, you need to make sure it's not interpreted as creating a list of characters to match. Make it the first character of the bracket expression: [-,.;/()_].



        Note that sed doesn't take the / as a separator for s/// if it's within a bracket expression, so there's no need to put a backslash in front of it. (The backslash will match itself.) E.g. echo 'ab/c' | sed 's/[/]/./g' prints a.b.c.



        See for example the regex(7) man page for a description of the regular expression syntax. (Note that it mainly discusses extended regular expressions (ERE), used by sed -E in many/most seds.)






        share|improve this answer













        To match all non-alphanumerics, use [^[:alnum:]]. It's similar to [^abc]: the leading caret makes the bracket expression match all but the listed characters.



        To match a literal dash, you need to make sure it's not interpreted as creating a list of characters to match. Make it the first character of the bracket expression: [-,.;/()_].



        Note that sed doesn't take the / as a separator for s/// if it's within a bracket expression, so there's no need to put a backslash in front of it. (The backslash will match itself.) E.g. echo 'ab/c' | sed 's/[/]/./g' prints a.b.c.



        See for example the regex(7) man page for a description of the regular expression syntax. (Note that it mainly discusses extended regular expressions (ERE), used by sed -E in many/most seds.)







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered May 12 at 15:28









        ilkkachuilkkachu

        64k10105183




        64k10105183



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Unix & Linux Stack Exchange!


            • 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%2funix.stackexchange.com%2fquestions%2f518553%2freplace-all-items-that-are-not-belong-to-characters-and-numbers-by%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

            Get product attribute by attribute group code in magento 2get product attribute by product attribute group in magento 2Magento 2 Log Bundle Product Data in List Page?How to get all product attribute of a attribute group of Default attribute set?Magento 2.1 Create a filter in the product grid by new attributeMagento 2 : Get Product Attribute values By GroupMagento 2 How to get all existing values for one attributeMagento 2 get custom attribute of a single product inside a pluginMagento 2.3 How to get all the Multi Source Inventory (MSI) locations collection in custom module?Magento2: how to develop rest API to get new productsGet product attribute by attribute group code ( [attribute_group_code] ) in magento 2

            Category:9 (number) SubcategoriesMedia in category "9 (number)"Navigation menuUpload mediaGND ID: 4485639-8Library of Congress authority ID: sh85091979ReasonatorScholiaStatistics

            Magento 2.3: How do i solve this, Not registered handle, on custom form?How can i rewrite TierPrice Block in Magento2magento 2 captcha not rendering if I override layout xmlmain.CRITICAL: Plugin class doesn't existMagento 2 : Problem while adding custom button order view page?Magento 2.2.5: Overriding Admin Controller sales/orderMagento 2.2.5: Add, Update and Delete existing products Custom OptionsMagento 2.3 : File Upload issue in UI Component FormMagento2 Not registered handleHow to configured Form Builder Js in my custom magento 2.3.0 module?Magento 2.3. How to create image upload field in an admin form