Ich muss alle Sonderzeichen, Satzzeichen und Leerzeichen aus einer Zeichenkette entfernen, so dass ich nur Buchstaben und Zahlen habe.
Antworten
Zu viele Anzeigen?
Vinay Kumar Kuresi
Punkte
11
import re
my_string = """Strings are amongst the most popular data types in Python. We can create the strings by enclosing characters in quotes. Python treats single quotes the
wie doppelte Anführungszeichen."""
# if we need to count the word python that ends with or without ',' or '.' at end
count = 0
for i in text:
if i.endswith("."):
text[count] = re.sub("^([a-z]+)(.)?$", r"\1", i)
count += 1
print("The count of Python : ", text.count("python"))
Viren Ramani
Punkte
63
Nach 10 Jahren habe ich unten geschrieben, dass es die beste Lösung ist. Sie können alle Sonderzeichen, Interpunktionszeichen, ASCII-Zeichen und Leerzeichen aus der Zeichenfolge entfernen/bereinigen.
from clean_text import clean
string = 'Special $#! characters spaces 888323'
new = clean(string,lower=False,no_currency_symbols=True, no_punct = True,replace_with_currency_symbol='')
print(new)
Output ==> 'Special characters spaces 888323'
you can replace space if you want.
update = new.replace(' ','')
print(update)
Output ==> 'Specialcharactersspaces888323'
Art Bindu
Punkte
521
function regexFuntion(st) {
const regx = /[^\w\s]/gi; // allow : [a-zA-Z0-9, space]
st = st.replace(regx, ''); // remove all data without [a-zA-Z0-9, space]
st = st.replace(/\s\s+/g, ' '); // remove multiple space
return st;
}
console.log(regexFuntion('$Hello; # -world--78asdf+-===asdflkj******lkjasdfj67;'));
// Output: Hello world78asdfasdflkjlkjasdfj67
Dsw Wds
Punkte
464
- See previous answers
- Weitere Antworten anzeigen