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

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

            Circuit construction for execution of conditional statements using least significant bitHow are two different registers being used as “control”?How exactly is the stated composite state of the two registers being produced using the $R_zz$ controlled rotations?Efficiently performing controlled rotations in HHLWould this quantum algorithm implementation work?How to prepare a superposed states of odd integers from $1$ to $sqrtN$?Why is this implementation of the order finding algorithm not working?Circuit construction for Hamiltonian simulationHow can I invert the least significant bit of a certain term of a superposed state?Implementing an oracleImplementing a controlled sum operation

            Magento 2 “No Payment Methods” in Admin New OrderHow to integrate Paypal Express Checkout with the Magento APIMagento 1.5 - Sales > Order > edit order and shipping methods disappearAuto Invoice Check/Money Order Payment methodAdd more simple payment methods?Shipping methods not showingWhat should I do to change payment methods if changing the configuration has no effects?1.9 - No Payment Methods showing upMy Payment Methods not Showing for downloadable/virtual product when checkout?Magento2 API to access internal payment methodHow to call an existing payment methods in the registration form?