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;
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
add a comment |
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
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
add a comment |
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
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
shell regular-expression
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
add a comment |
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
add a comment |
1 Answer
1
active
oldest
votes
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.)
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.)
add a comment |
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.)
add a comment |
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.)
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.)
answered May 12 at 15:28
ilkkachuilkkachu
64k10105183
64k10105183
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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