This should work: [^a-zA-Z0-9]. Replace that with nothing. — Kevin AirDev We’re looking for Bubble developers to join our team: https://jobs.airdev.co/ Answer from kevin12 on forum.bubble.io
🌐
Bubble
forum.bubble.io › need help
What is the regex pattern to remove all characters except numbers and letters? - Need help - Bubble Forum
January 23, 2020 - I am not good with regex. What is the pattern to remove all spaces, tabs, dashes, and all other non- number or letter characters easily from a string?
🌐
Ablebits
ablebits.com › ablebits blog › excel › regex › regex to remove certain characters or text in excel
Excel Regex to remove certain characters or text from strings
August 22, 2023 - For instance, to strip off any character other than a letter, digit, period, comma, or space, use the following regex: ... This successfully eliminates all special characters, but extra whitespace remains.
Discussions

removing all non-letter characters from a string? ((using regex))
This is very simple with regex. You just need to replace non-words (/\W/ig). So: var string = "lakjsdlkasjdlsaj@£$%^&*klajdlaskjds"; string.replace(/\W/ig, ""); --> "lakjsdlkasjdlsajklajdlaskjds" \w == words, \W == non words. You don't need a loop here as we're using /g which stands for global, so we replace every instance. And just incase I'm using /i as well which ignores the case. As it's regex you can just do /ig and the selectors will stack to ignore case and global. My favorite regex visualiser lives here: https://jex.im/regulex/#!embed=false&flags=ig&re=%5CW More on reddit.com
🌐 r/learnjavascript
10
4
September 28, 2015
java - Regular Expression to remove everything but characters and numbers - Stack Overflow
Copypublic class RegexFun2 { public ... test.replaceAll(regex, ""); System.out.println(result); } } But still I think the OP is cheating himself by not demonstrating that he tried first and posting his attempt in his original question. Just my 2 cents. ... Save this answer. ... Show activity on this post. ... to remove everything but characters ... More on stackoverflow.com
🌐 stackoverflow.com
regex - Remove all characters except - Code Review Stack Exchange
My code takes a string and replaces all characters which are not: English letters Numbers , / - I have tested it and it seems to generally work well enough. But it may have some catastrophic bug in... More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
October 5, 2017
Regex to Remove Everything but Numbers, Letters and Spaces in R - Stack Overflow
How can I remove these pesky backslashes in R? I've scoured the web and stackoverflow to try to find a way to get rid of backslashes...no luck. I've tried a lot of different ways, but I think the ... More on stackoverflow.com
🌐 stackoverflow.com
April 25, 2017
Top answer
1 of 4
58

You can use regex

myString.replace(/[^\w\s!?]/g,'');

This will replace everything but a word character, space, exclamation mark, or question.

Character Class: \w stands for "word character", usually [A-Za-z0-9_]. Notice the inclusion of the underscore and digits.

\s stands for "whitespace character". It includes [ \t\r\n].

If you don't want the underscore, you can use just [A-Za-z0-9].

myString.replace(/[^A-Za-z0-9\s!?]/g,'');

For unicode characters, you can add something like \u0000-\u0080 to the expression. That will exclude all characters within that unicode range. You'll have to specify the range for the characters you don't want removed. You can see all the codes on Unicode Map. Just add in the characters you want kept or a range of characters.

For example:

myString.replace(/[^A-Za-z0-9\s!?\u0000-\u0080\u0082]/g,'');

This will allow all the previously mentioned characters, the range from \u0000-\u0080 and \u0082. It will remove \u0081.

2 of 4
7

Both answers posted so far left out the question mark. I would comment on them, but don't have enough rep yet.

David is correct, sachleen's regex will leave underscores behind. rcdmk's regex, modified as follows, will do the trick, although if you care about international characters things might get a lot more complicated.

var result = text.replace(/[^a-zA-Z0-9\s!?]+/g, '');

This will leave behind new lines and tabs as well as spaces. If you want to get rid of new lines and tabs as well, change it to:

var result = text.replace(/[^a-zA-Z0-9 !?]+/g, '');
🌐
Reddit
reddit.com › r/learnjavascript › removing all non-letter characters from a string? ((using regex))
r/learnjavascript on Reddit: removing all non-letter characters from a string? ((using regex))
September 28, 2015 -

I am currently trying this two different ways and they aren't working - I'm checking the input value and running this every time a key is pressed:

input.replace(/[^a-zA-z]/, "");

and

for(var i = 0; i < input.length; i++){
	   if( input[i] ==  /[^a-zA-z]/g){
	   	console.log("input " + input[i] + " is not a letter!");
	    	input.replace(input[i], "");
	   }
	}

jsfiddle here

🌐
GeeksforGeeks
geeksforgeeks.org › python-remove-all-characters-except-letters-and-numbers
Remove All Characters Except Letters and Numbers - Python - GeeksforGeeks
April 19, 2025 - In this article, we’ll learn how to clean a string by removing everything except letters (A–Z, a–z) and numbers (0–9).
🌐
TutorialsPoint
tutorialspoint.com › python-remove-all-characters-except-letters-and-numbers
Python - Remove all characters except letters and numbers
September 20, 2021 - When it is required to remove all characters except for letters and numbers, regular expressions are used. A regular expression is defined, and the string is subjected to follow this expression. Example Below is a demonstration of th
Find elsewhere
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-remove-all-characters-except-numbres
Remove all non-numeric characters from String in JavaScript | bobbyhadz
The part between the square brackets [] is called a character class and matches everything except for digits and dots. The caret ^ symbol in the regex means "NOT the following".
🌐
Notepad++ Community
community.notepad-plus-plus.org › topic › 26186 › notepad-remove-everything-except-a-specific-string-using-regex
[Notepad++] Remove everything except a specific string using regex | Notepad++ Community
October 11, 2024 - you could use a combination of \K control flow escape (which says the stuff to the left of this symbol must match, but I don’t want it replaced by the replacement) and a lookahead assertion: FIND = A1\KB(?=A2) , REPLACE = empty · (A1, B, and A2 are meant to be placeholders, which would need to be real regex
🌐
Bubble
forum.bubble.io › need help
How to remove anything except letters and numbers? - Need help - Bubble Forum
December 14, 2017 - Hey guys, I have one field like Name: Then I have another one like: Name2: I want to get the data that the user typed into Name field, and put it into Name2, but removing anything except letters (e.g.: special charact…