6

Remove all except alphanumeric spaces

 3 years ago
source link: https://www.codesd.com/item/remove-all-except-alphanumeric-spaces.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Remove all except alphanumeric spaces

advertisements

I have a string that has some special characters and spaces. I can remove the special characters, but how can I make it so it keeps the spaces?

var a = "dent's dc^e co cbs";

var re = /\W/g;

b = a.replace(re, '');

console.log(b);

The way it is, it just deletes everything. And it broke when I tried to add (^\s) after the W


You can use negated character class with \w, and \s:

var re = /[^\w ]/g;

  • [^\w] gives you same effect as \W
  • Addition of an empty space " " in negated character class, also negates space.

Related Articles

Regex to remove all non-alphanumeric spaces and replace with +

I'm looking to use regex to try remove all non alpha-numeric characters from a string and replace spaces with a + All I want to permit is basically alphabetical words A-Z and + This is specifically to prepare the string to become a part of a URL, thu

Regular Java expression to remove all non-alphanumeric characters EXCEPT spaces

I'm trying to write a regular expression in Java which removes all non-alphanumeric characters from a paragraph, except the spaces between the words. This is the code I've written: paragraphInformation = paragraphInformation.replaceAll("[^a-zA-Z0-9\s

php regex removes all non-alphanumeric characters and spaces from a string

I need a regex to remove all non-alphanumeric and space characters, I have this $page_title = preg_replace("/[^A-Za-z0-9 ]/", "", $page_title); but it doesn't remove space characters and replaces some non-alphanumeric characters with n

How do I remove all the back space of the word (blank space before and end) in a string separated by commas

My string is like this: Abc , xyz , pqr Final output: Abc,xyz,pqr i want to remove all trailing space(from front and end) from my word whenever i encounter comma in my string but condittion is if my string contain comma or space. Eg: Abc pqr, ttt ooo

Unique function to remove all kinds of spaces

I need a php function to remove all the whitespaces in a string. I tried str_replace(" ","",$str); Then I tried rtrim(); But even then I can't remove the spaces that are formed by the I tried str_replace(" ","",$str

How do I remove all unnecessary blank spaces in a string?

I pull some text from a website and save it in an NSString, and display it back to the user, but I want it in one clear line, one word after another word, with absolutely zero line-breaks or unnecessary whitespace or tabs. Take the following image: B

Regex to remove all non-alphanumeric characters with universal language support?

I would like to use Pattern's compile method to do this. Such as String text = "Where? What is that, an animal? No! It is a plane."; Pattern p = new Pattern("*some regex here*"); String delim = p.matcher(text).replaceAll("");

Regex find and replace: remove all * except * match

I'm using Notepad++ to remove everything from HTML except an id matching ('idxxxxxx'). Here's (part of) the HTML: { href : "/id123456", title : "Book 1", year : "2013", }, { href : "/id234567", title : "Book 2&

Remove all after the space in the SQL Server data column

I have a data column in SQL Server that always starts with a number and sometimes has a space after the number with additional details. This is a text column. I need a query that will remove everything after and including space if there is a space or

How do I remove all non-alphanumeric characters and leading zeros

I want to remove everything from a string using regular expression except alpha and numeric characters and I need any leading zero removed. The below works but does not remove leading zeros $string = '00000000A1234567890-=qwesss €#¢∞§¶¶•ªº– ≠≠rtyuuio

How to remove all white space in java

This question already has an answer here: Removing whitespace from strings in Java 25 answers I have a programming assignment and part of it requires me to make code that reads a line from the user and removes all the white space within that line. th

Get a Substring in SQL between two characters and remove all white spaces

I've a strings such as: Games/Maps/MapsLevel1/Level 1.swf Games/AnimalWorld/Animal1.1/Level 1.1.swf Games/patterns and spatial understanding/Level 13.5/Level 13.5.swf I want to get only file name without its extension(String After last Slash and befo

How to remove all white space from a given text file

I want to remove all the white spaces from a given text file. Is there any shell command available for this ? Or, how to use sed for this purpose. I want something like below: $ cat hello.txt | sed .... I tried this : cat hello.txt | sed 's/ //g' .Bu

Removes all characters from variable String but letters

This question already has an answer here: How do I remove all non alphanumeric characters from a string except dash? 9 answers I want to write a function that removes all characters in a string variables but leaves only the letters. For example, if t

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK