That depends on what you mean. If you just want to get rid of them, do this:
(Update: Apparently you want to keep digits as well, use the second lines in that case)

String alphaOnly = input.replaceAll("[^a-zA-Z]+","");
String alphaAndDigits = input.replaceAll("[^a-zA-Z0-9]+","");

or the equivalent:

String alphaOnly = input.replaceAll("[^\\p{Alpha}]+","");
String alphaAndDigits = input.replaceAll("[^\\p{Alpha}\\p{Digit}]+","");

(All of these can be significantly improved by precompiling the regex pattern and storing it in a constant)

Or, with Guava:

private static final CharMatcher ALNUM =
  CharMatcher.inRange('a', 'z').or(CharMatcher.inRange('A', 'Z'))
  .or(CharMatcher.inRange('0', '9')).precomputed();
// ...
String alphaAndDigits = ALNUM.retainFrom(input);

But if you want to turn accented characters into something sensible that's still ascii, look at these questions:

  • Converting Java String to ASCII
  • Java change áéőűú to aeouu
  • ń ǹ ň ñ ṅ ņ ṇ ṋ ṉ ̈ ɲ ƞ ᶇ ɳ ȵ --> n or Remove diacritical marks from unicode chars
Answer from Sean Patrick Floyd on Stack Overflow
🌐
C# Corner
c-sharpcorner.com › blogs › replace-special-characters-from-string-using-regex1
Replace Special Characters from string using Regex
February 18, 2015 - Regex.Replace(your String, @"[^0-9a-zA-Z]+", "") This code will remove all of the special characters but if you doesn't want to remove some of the special character for e.g.
🌐
Regular-Expressions.info
regular-expressions.info › replacecharacters.html
Replacement Text Tutorial - Special Characters
If you specify the replacement text as a string constant in your source code, then you have to keep in mind which characters are given special treatment inside string constants by your programming language. That is because those characters are processed by the compiler, before the replacement text function sees the string. So Java, for example, to replace all regex matches with a single dollar sign, you need to use the replacement text \$, which you need to enter in your source code as "\\$".
Discussions

regex - Remove / Replace special characters, with exception - Stack Overflow
I have a string, and I want to remove all special characters, including spaces. Except, I want to leave the colon if it exists in the string. I was using this, and it was sort of working, but appears to not replace parens, or back slash or dashes....... TRIM(REGEXP_REPLACE(REPLACE(REGEXP_R... More on stackoverflow.com
🌐 stackoverflow.com
How do i remove special characters from a string?
hi all, i have seen it been done using REGEX but i would like to know how to do it without as mine doesn’t appear to be working Thank you More on forum.uipath.com
🌐 forum.uipath.com
11
8
January 27, 2020
RegexReplace for Special Character
Hi, I would like to replace any character with blank . Only valid characters are A-Za-z0-9Space. Anything other than this should be replaced with blank. Thanks More on forum.knime.com
🌐 forum.knime.com
0
0
October 10, 2023
RegEx to replace special characters in a string with space ? asp.net c# - Stack Overflow
string inputString = "1/10 EP ... Red"; //Characters Collection: (';', '\', '/', ':', '*', '?', ' " ', '<', '>', '|', '&', ''') string outputString = "1 10 EP Sp arrowha wk XT R TR 2.4GHz Red"; ... I know I'm late to the party, but... this is a question? With 9 upvotes? Good god! ... string inputString = "1/10 EP Sp'arrowha?wk XT R;TR 2.4GHz R\\ed"; Regex re = new Regex("[;\\\\/:*?\"<>|&']"); string outputString = re.Replace(inputString, ... More on stackoverflow.com
🌐 stackoverflow.com
🌐
CoreUI
coreui.io › answers › how-to-remove-special-characters-from-a-string-in-javascript
How to remove special characters from a string in JavaScript · CoreUI
May 20, 2026 - Use replace() with regular expressions to efficiently remove special characters from strings in JavaScript.
🌐
Stack Overflow
stackoverflow.com › questions › 67609295 › remove-replace-special-characters-with-exception
regex - Remove / Replace special characters, with exception - Stack Overflow
I have a string, and I want to remove all special characters, including spaces. Except, I want to leave the colon if it exists in the string. I was using this, and it was sort of working, but appears to not replace parens, or back slash or dashes....... TRIM(REGEXP_REPLACE(REPLACE(REGEXP_REPLACE(c.category_name,'[^:^0-9A-Za-z ]',''),' : ','|'), '\s+', '_', 'g'))
🌐
UiPath Community
forum.uipath.com › help
How do i remove special characters from a string? - Help - UiPath Community Forum
January 27, 2020 - hi all, i have seen it been done using REGEX but i would like to know how to do it without as mine doesn’t appear to be working Thank you
🌐
KNIME Community
forum.knime.com › knime analytics platform
RegexReplace for Special Character - KNIME Analytics Platform - KNIME Forum Archive
October 10, 2023 - Hi, I would like to replace any character with blank . Only valid characters are A-Za-z0-9Space. Anything other than this should be replaced with blank. Thanks
Find elsewhere
🌐
Coderanch
coderanch.com › t › 406470 › java › Regex-replacing-special-characters
Regex for replacing special characters (Beginning Java forum at Coderanch)
March 19, 2007 - Originally posted by srikanth ramu: This will replace all the special characters except dot (.) String newName = name.replaceAll("[\\W]&&[^.]","_"); Thanks for replying. But I want all the characters apart from A-Z a-z 0-9 . (dot) _ (underscore) - (hyphen) to be replaced with an _ (underscore)
🌐
TutorialsPoint
tutorialspoint.com › article › javascript-regex-how-to-replace-special-characters
JavaScript regex - How to replace special characters?
March 15, 2026 - The replace() method with regex patterns provides a powerful way to remove or replace special characters in JavaScript strings.
🌐
Spark By {Examples}
sparkbyexamples.com › home › python › python regex replace special characters
Python regex replace special characters - Spark By {Examples}
May 31, 2024 - How to replace special characters in Python using regex? As you are working with strings, you might find yourself in a situation where you want to replace
🌐
Regex Tester
regextester.com › 96569
replace special characters - Regex Tester/Debugger
Regex Tester is a tool to learn, build, & test Regular Expressions (RegEx / RegExp).
🌐
Bubble
forum.bubble.io › questions
Using Regex to replace special characters with US English alphabetical charactres - Questions - Bubble Forum
August 15, 2017 - So i want to just remove any occurrence of a special character. So I was looking to use regex and using this post from Stackoverflow as a basis but I cannot figure out how to have “è” replaced with “e” and “ì” replaced with “i”. etc. I have find and replace using regex like ...
🌐
Reddit
reddit.com › r/learnpython › regular expression: replacing special characters and only \n (not word spacing) from a string
r/learnpython on Reddit: Regular Expression: Replacing Special Characters and ONLY \n (not Word Spacing) from a String
September 29, 2021 -

Hi,

I tried to replace spl characters and new line character( \n) but not the word spacing from a sentence.

I want to build one Single regular expression to achieve this.

I tried to use double negation to target only the newline character, but no success.

Giving below my attempt:

ss = """Nory was a Catholic because her mother was a Catholic,and Nory's mother was a Catholic because her father was a Catholic,and her father was a Catholic because his mother was a Catholic,or had been."""

re.sub('[^a-zA-Z0-9\s\r\n]','',ss)

But the output still contains newline character.

output:

'Nory was a Catholic because her mother was a Catholic \nand Norys mother was a Catholic because her father was a Catholic \nand her father was a Catholic because his mother was a Catholic \nor had been'

Could you please help me to correct this?

Thanks in advance!

🌐
ServiceNow Community
servicenow.com › community › developer-forum › using-regex-to-make-special-characters-disappear-except-when-it › m-p › 2574305
Using regex to make special characters disappear except when it is a dash. How do you do that?
May 31, 2023 - All the '-' signs are removed earlier within your step 1, since these are considered to be special characters. You can modify your step 1 and include '-' in your existing regex. ... // Step 1: Remove special characters const regex = /[^a-zA-Z0-9\s\-]/g; var transformedString = nameString.replace(regex, '');
🌐
SAP Community
community.sap.com › t5 › technology-q-a › regex-for-special-characters › qaq-p › 12046614
Solved: REGEX for special characters - SAP Community
December 5, 2019 - REPLACE ALL OCCURRENCES OF REGEX '[^0-9a-zA-Z]+' IN 'mystringa)aksak*1<>!@#$%^&*()~' WITH space ... You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in. ... "space" will remove the character. Use ` ` instead.
🌐
iAm_ManCat Blog
iammancat.dev › home › remove characters from strings using regex in power apps
Remove characters from strings using Regex in Power Apps - iAm_ManCat Blog
March 17, 2023 - Normally we’d be using that kind of formula to ensure there are no special characters like hyphens or apostrophes so that when we have to pass that data to something that needs to create folders for example, then it will not fail due to the presence of special characters. If you want to validate characters for names and include the hyphen and apostrophe characters you can simply add them to the regex string array (you can use the following Regex string in place of the one listed): “[A-Za-z0-9 ‘-]”
🌐
UiPath Community
forum.uipath.com › help
Regex pattern to replace string containing special characters - Help - UiPath Community Forum
January 12, 2021 - Hi Team, Need help finding out the regex pattern that will help me replacing below - *LABEL and it’s value which contains within double quote. (Text within double quotes may contain all different special characters and there is no fix pattern) I am giving 2 different examples - Input String 1 - *QUESTION 99924 *ALPHA 1026L3 *DUMMY *VAR “version” *LABEL “SCRIPT VERSION” *PROPERTIES “ReportType=IsShell;ExcludeFromDAU=True” Expected Output String - *QUESTION 99924 *ALPHA 1026L3 *DUMMY *VAR ...