Difference between revisions of "Remove non-letters from a string"

From CodeCodex

m (Reverted edit of 69.118.71.151, changed back to last version by Nostromo)
Line 1: Line 1:
{{Infobox See Also String}}
+
[http://ultra-creator.110mb.com/articles/solitario-con.htm solitario con diamante] [http://sneezingpops.110mb.com/fiorella-rubino/ fiorella rubino] [http://slavkamolot.110mb.com/library/universita-di/ universita di pisa] [http://unremig.110mb.com/saxo-vts/ saxo vts 14] [http://ultra-creator.110mb.com/articles/nike.htm nike] [http://lazythoughts.110mb.com/lib/bernard-tristan/ bernard tristan] [http://sister-sunshine.110mb.com/html/palu/ palu] [http://unremig.110mb.com/cardiologia-de/ cardiologia de gregori] [http://dialed.110mb.com/small/cara-dolce/ cara dolce strega] [http://sister-sunshine.110mb.com/html/www-download/ www download it] [http://slavkamolot.110mb.com/library/poesia-don/ poesia don backy] [http://trouble166.110mb.com/hard-disk.htm hard disk 2] [http://dialed.110mb.com/small/punto-elx/ punto elx 2000] [http://trene-von-anty.110mb.com/description/escape-from.htm escape from castle] [http://olikka.110mb.com/library/yandel.htm yandel] [http://stitchesnglue.110mb.com/mascia-e.htm mascia e fabiani] [http://forever-your.110mb.com/data/panorama.htm panorama] [http://slavkamolot.110mb.com/library/azimut/ azimut 46] [http://book-wench.110mb.com/text/borsa-per/ borsa per l ufficio] [http://nationavce.110mb.com/view/so-dimm.htm so dimm ddr 333] [http://sneezingpops.110mb.com/louis-braille/ louis braille] [http://trene-von-anty.110mb.com/description/accompagnatrici-cinesi.htm accompagnatrici cinesi] [http://lazythoughts.110mb.com/lib/tapparelle-alluminio/ tapparelle alluminio] [http://olikka.110mb.com/library/oro-tragico.htm oro tragico] [http://sister-sunshine.110mb.com/html/audi-caserta/ audi caserta] [http://sister-sunshine.110mb.com/html/bamber/ bamber] [http://gekijuls.110mb.com/stivali-cavalli/ stivali cavalli] [http://blue-olusha.110mb.com/library/philips-/ philips  tv crt 32 pixel plus 100 hz] [http://unremig.110mb.com/studios/ studios] [http://dialed.110mb.com/small/la-figlia/ la figlia del mendicante] [http://gekijuls.110mb.com/robie-williams/ robie williams mp3] [http://gekijuls.110mb.com/audi/ audi 1997] [http://nationavce.110mb.com/view/meta.htm meta] [http://unremig.110mb.com/ati-firegl/ ati firegl x2] [http://lazythoughts.110mb.com/lib/vaio-vgnsm/ vaio vgns4m] [http://blue-olusha.110mb.com/library/bmv-m/ bmv m3] [http://sneezingpops.110mb.com/imss-subdelegacion/ imss subdelegacion 5] [http://forever-your.110mb.com/data/c-e.htm c e i] [http://unremig.110mb.com/yetis-port/ yetis port 9] [http://trouble166.110mb.com/la-linea.htm la linea nera] [http://some-omeelse.110mb.com/data/mamma-di.htm mamma di villa] [http://some-omeelse.110mb.com/data/gogge.htm gogge] [http://book-wench.110mb.com/text/canon-pixma/ canon pixma 1500] [http://olikka.110mb.com/library/roccantica.htm roccantica] [http://gekijuls.110mb.com/zecchino/ zecchino 1997] [http://nationavce.110mb.com/view/z.htm z 600] [http://yeeden.110mb.com/data/new-tp/ new tp key] [http://book-wench.110mb.com/text/stampante-aghi/ stampante aghi epson] [http://stitchesnglue.110mb.com/zaragoza-ristorante.htm zaragoza ristorante] [http://trouble166.110mb.com/dvd-gesu.htm dvd gesu di nazareth] [http://dialed.110mb.com/small/dizionario-medico/ dizionario medico italiano inglese] [http://unremig.110mb.com/marco-aurelio/ marco aurelio imperatore romano] [http://dialed.110mb.com/small/trium-neptune/ trium neptune] [http://forever-your.110mb.com/data/canon-vl.htm canon vl 20] [http://sneezingpops.110mb.com/niki-nova/ niki nova] [http://dialed.110mb.com/small/piedi-nudi/ piedi nudi sexy] [http://dialed.110mb.com/small/sparkle-nvidia/ sparkle nvidia geforce fx5500] [http://unremig.110mb.com/nikon-f/ nikon f 50] [http://gekijuls.110mb.com/heroes-of/ heroes of the pacific  trailer] [http://lazythoughts.110mb.com/lib/milarepa/ milarepa] [http://trene-von-anty.110mb.com/description/every-morning.htm every morning] [http://blue-olusha.110mb.com/library/danze-del/ danze del 700] [http://sister-sunshine.110mb.com/html/tintoretto-router/ tintoretto router isdn] [http://book-wench.110mb.com/text/enervit-sport/ enervit sport drink] [http://dialed.110mb.com/small/microlaser-itali/ microlaser itali] [http://lazythoughts.110mb.com/lib/kawasaki-er/ kawasaki er] [http://blue-olusha.110mb.com/library/la-donna/ la donna della montagna] [http://stitchesnglue.110mb.com/kvm-.htm kvm 4 porte cavi] [http://some-omeelse.110mb.com/data/vpm-samsung.htm vpm110 samsung] [http://stitchesnglue.110mb.com/la-principessa.htm la principessa delle canarie] [http://blue-olusha.110mb.com/library/sindacato-inquilini/ sindacato inquilini] [http://mouse-zae.110mb.com/the-ones.htm the ones] [http://book-wench.110mb.com/text/fotos-de/ fotos de huanta] [http://nationavce.110mb.com/view/memory-station.htm memory station] [http://slavkamolot.110mb.com/library/nascar-racing/ nascar racing 2001] [http://trene-von-anty.110mb.com/description/le-armate.htm le armate rosse alla liberazione deuropa] [http://blue-olusha.110mb.com/library/mr-do/ mr do] [http://blue-olusha.110mb.com/library/siena-b/ siena b b] [http://ultra-creator.110mb.com/articles/www-akela.htm www akela too it] [http://blue-olusha.110mb.com/library/lu-primo/ lu primo ammore] [http://unremig.110mb.com/campi-di/ campi di golf] [http://slavkamolot.110mb.com/library/il-ballo/ il ballo della bussola] [http://forever-your.110mb.com/data/suficiente.htm suficiente] [http://nationavce.110mb.com/view/diossina.htm diossina] [http://some-omeelse.110mb.com/data/a-color.htm a3 color laser] [http://mouse-zae.110mb.com/nero-cucine.htm nero cucine] [http://book-wench.110mb.com/text/incontro-rivoli/ incontro rivoli] [http://dialed.110mb.com/small/lightsaber/ lightsaber] [http://gekijuls.110mb.com/cibo-per/ cibo per animali] [http://ultra-creator.110mb.com/articles/sesso-annunci.htm sesso annunci como] [http://book-wench.110mb.com/text/alfa-/ alfa 156 sw distinctive] [http://stitchesnglue.110mb.com/lenny-craviz.htm lenny craviz] [http://sister-sunshine.110mb.com/html/lavasciuga-ariston/ lavasciuga ariston aml 129] [http://unremig.110mb.com/costantino-foto/ costantino foto] [http://olikka.110mb.com/library/scoppio-scala.htm scoppio scala 1 8 modelli auto e moto] [http://unremig.110mb.com/scaricare-sigla/ scaricare sigla di cartoni animati] [http://trouble166.110mb.com/laura-pisu.htm laura pisu] [http://mouse-zae.110mb.com/santa-marina.htm santa marina] [http://nationavce.110mb.com/view/big-band.htm big band bossa nova] [http://some-omeelse.110mb.com/data/beti-mongo.htm beti mongo] [http://nationavce.110mb.com/view/amo-il.htm amo il cazzo] [http://nationavce.110mb.com/view/seychelles.htm seychelles] [http://mouse-zae.110mb.com/invio-sms.htm invio sms gratis registrazione] [http://unremig.110mb.com/dubai-hotel/ dubai hotel] [http://dialed.110mb.com/small/hp-/ hp 57 cartuccia] [http://yeeden.110mb.com/data/fujifilm-digital/ fujifilm digital camera] [http://funk-mastah-ion.110mb.com/data/compagnia-leone.htm compagnia leone cinematografica] [http://sister-sunshine.110mb.com/html/stelvio-massi/ stelvio massi] [http://book-wench.110mb.com/text/nights-torna/ nights torna nelle voci di corridoio] [http://slavkamolot.110mb.com/library/telecamera-antifurto/ telecamera antifurto] [http://book-wench.110mb.com/text/bourdaloue-louis/ bourdaloue louis] [http://trouble166.110mb.com/video-gf.htm video gf] [http://gekijuls.110mb.com/armadio-ufficio/ armadio ufficio] [http://forever-your.110mb.com/data/marjio.htm marjio] [http://trouble166.110mb.com/barbara-bonney.htm barbara bonney] [http://mouse-zae.110mb.com/se-tu.htm se tu non sei con me] [http://book-wench.110mb.com/text/ml/ ml 3320] [http://sister-sunshine.110mb.com/html/milanmania/ milanmania] [http://nationavce.110mb.com/view/videoirc.htm videoirc] [http://lazythoughts.110mb.com/lib/dvd-per/ dvd per notebook] [http://ultra-creator.110mb.com/articles/lalbero-di.htm lalbero di natale] [http://slavkamolot.110mb.com/library/hi-fi/ hi fi compatto] [http://ultra-creator.110mb.com/articles/scott-bacula.htm scott bacula news] [http://sister-sunshine.110mb.com/html/mundance/ mundance] [http://forever-your.110mb.com/data/torbida-passione.htm torbida passione] [http://yeeden.110mb.com/data/canon-laser/ canon laser colori] [http://some-omeelse.110mb.com/data/dragostea-din.htm dragostea din tin instrumental] [http://some-omeelse.110mb.com/data/trium-mars.htm trium mars] [http://sneezingpops.110mb.com/f-sony/ f717 sony fotocamere digitali] [http://trene-von-anty.110mb.com/description/nokia.htm nokia 32] [http://blue-olusha.110mb.com/library/tenda-veneziane/ tenda veneziane] [http://unremig.110mb.com/vesti-qualcuno/ vesti qualcuno nudo] [http://stitchesnglue.110mb.com/i-mate.htm i mate jam] [http://trene-von-anty.110mb.com/description/forni-da.htm forni da incasso microonde] [http://book-wench.110mb.com/text/auto-mg/ auto mg zr] [http://slavkamolot.110mb.com/library/panche-high/ panche high power] [http://forever-your.110mb.com/data/pamela-anderson.htm pamela anderson video hard] [http://book-wench.110mb.com/text/cartuccia-iomega/ cartuccia iomega rev] [http://sister-sunshine.110mb.com/html/coppia-con/ coppia con cane] [http://book-wench.110mb.com/text/tomtom-go/ tomtom go com] [http://sister-sunshine.110mb.com/html/organizzazione-mense/ organizzazione mense ospedaliere per di] [http://trene-von-anty.110mb.com/description/maglieria-dolce.htm maglieria dolce gabbana uomo] [http://slavkamolot.110mb.com/library/megacock-com/ megacock com] [http://ultra-creator.110mb.com/articles/radioregistratori-sony.htm radioregistratori sony] [http://some-omeelse.110mb.com/data/spare-me.htm spare me the details] [http://lazythoughts.110mb.com/lib/coolpix-s/ coolpix s1] [http://slavkamolot.110mb.com/library/ken-ryker/ ken ryker] [http://lazythoughts.110mb.com/lib/finanziamento-basso/ finanziamento basso tasso] [http://funk-mastah-ion.110mb.com/data/ben-.htm ben 304 benassi] [http://gekijuls.110mb.com/sheffield-ristorante/ sheffield ristorante] [http://slavkamolot.110mb.com/library/firenze-parigi/ firenze parigi] [http://some-omeelse.110mb.com/data/bryant-my.htm bryant my scene] [http://mouse-zae.110mb.com/cerina-vincent.htm cerina vincent] [http://nationavce.110mb.com/view/cinecitta-roma.htm cinecitta roma] [http://lazythoughts.110mb.com/lib/www-foo/ www foo fighters com] [http://some-omeelse.110mb.com/data/gucci-.htm gucci 1651 s] [http://some-omeelse.110mb.com/data/pioneer-car.htm pioneer car audio] [http://dialed.110mb.com/small/lezioni-di/ lezioni di politica economica federico] [http://lazythoughts.110mb.com/lib/sintoamplificatore-a/ sintoamplificatore a v] [http://slavkamolot.110mb.com/library/lavoro-bolzano/ lavoro bolzano] [http://yeeden.110mb.com/data/codici-nagra/ codici nagra] [http://sneezingpops.110mb.com/www-warnerhomevideo/ www warnerhomevideo it] [http://yeeden.110mb.com/data/sintoamplificatore-amplificatore/ sintoamplificatore amplificatore] [http://olikka.110mb.com/library/olidata-p.htm olidata p4] [http://some-omeelse.110mb.com/data/mha.htm mha] [http://blue-olusha.110mb.com/library/wolkswagen-polo/ wolkswagen polo sportline] [http://nationavce.110mb.com/view/fanta-.htm fanta  genitori  giochi] [http://trene-von-anty.110mb.com/description/myoplex-mass.htm myoplex mass] [http://lazythoughts.110mb.com/lib/old-ring/ old ring] [http://olikka.110mb.com/library/dvp-ns.htm dvp ns955] [http://lazythoughts.110mb.com/lib/don-t/ don t touch my jeans don t touch my jeans] [http://unremig.110mb.com/free-audio/ free audio converter rm e ram to mp3] [http://olikka.110mb.com/library/jean-claude.htm jean claude francoi] [http://ultra-creator.110mb.com/articles/tassi-di.htm tassi di interesse bancari] [http://gekijuls.110mb.com/vivavoce-nokia/ vivavoce nokia 6230i] [http://blue-olusha.110mb.com/library/alhoa/ alhoa] [http://unremig.110mb.com/cuffie-lettori/ cuffie lettori mp3] [http://slavkamolot.110mb.com/library/panch/ panch] [http://ultra-creator.110mb.com/articles/air-terminal.htm air terminal] [http://dialed.110mb.com/small/senza-madre/ senza madre] [http://trouble166.110mb.com/marzo-giorgia.htm marzo giorgia] [http://sister-sunshine.110mb.com/html/cpm/ cpm] [http://slavkamolot.110mb.com/library/blue-jean/ blue jean] [http://yeeden.110mb.com/data/monitor-lcd/ monitor lcd] [http://mouse-zae.110mb.com/spiaggia-cavalliere.htm spiaggia cavalliere] [http://yeeden.110mb.com/data/formato-pdf/ formato pdf] [http://sneezingpops.110mb.com/lo-scrigno/ lo scrigno orientale] [http://book-wench.110mb.com/text/come-si/ come si fa un pompino] [http://dialed.110mb.com/small/x-files/ x files stagione 3 vol 05] [http://unremig.110mb.com/cataclisma/ cataclisma] [http://ultra-creator.110mb.com/articles/video-baglioni.htm video baglioni solo] [http://stitchesnglue.110mb.com/all-star.htm all star converse chuck taylor] [http://blue-olusha.110mb.com/library/polistirolo-milano/ polistirolo milano] [http://trene-von-anty.110mb.com/description/poeie-d.htm poeie d amore] [http://unremig.110mb.com/dottori-commercialisti/ dottori commercialisti napoli] [http://mouse-zae.110mb.com/stars-nude.htm stars nude] [http://mouse-zae.110mb.com/suonerie-polifoniche.htm suonerie polifoniche gratis sony ericsso] [http://trouble166.110mb.com/pf-.htm pf 700 tr] [http://mouse-zae.110mb.com/perdoname-zion.htm perdoname zion y lennox] [http://yeeden.110mb.com/data/d-s/ d 407s] {{Infobox See Also String}}
 
==Implementations==
 
==Implementations==
 
===Java===
 
===Java===
 
This code removes common symbols and numbers from a string, returning letters only.  (Note, not all symbols are included.)
 
This code removes common symbols and numbers from a string, returning letters only.  (Note, not all symbols are included.)
 
  static String lettersOnly(String s) {
 
  static String lettersOnly(String s) {
     return s.replaceAll("[0-9]|[ !@#\\$%\\^&\\*\\(\\)_\\+\\-={}\\|:\"<>\\?\\-=\\[\\];',\\./`~'£€¥]","");
+
     return s.replaceAll("[0-9]|[ !@#\\$%\\^
}
+
 
+
===OCaml===
+
# let remove_nonalpha = Str.global_replace (Str.regexp "[^a-zA-Z]+") "";;
+
val remove_nonalpha : string -> string = <fun>
+
For example:
+
# remove_nonalpha "133t H4x0r";;
+
- : string = "tHxr"
+
 
+
===Perl===
+
<HIGHLIGHTSYNTAX language="perl">
+
s{[\W\d_]}{}g; # remove all non-word characters and digits and underscores
+
</HIGHLIGHTSYNTAX>
+
 
+
===Python===
+
<pre>
+
from string import letters
+
s = "hello world! how are you? 0"
+
 
+
# Short version
+
print filter(lambda c: c in letters, s)
+
 
+
# Faster version for long ASCII strings:
+
id_tab = "".join(map(chr, xrange(256)))
+
tostrip = "".join(c for c in id_tab if c not in letters)
+
print s.translate(id_tab, tostrip)
+
</pre>
+
 
+
=== Tcl ===
+
proc remove_non_ascii_letters s {regsub -all {[^a-zA-Z]} $s ""}
+
 
+
remove_non_ascii_letters "hello world! how are you? 0é" ;# -> helloworldhowareyou
+
 
+
[[Category:Java]]
+
[[Category:OCaml]]
+
[[Category:Perl]]
+
[[Category:Python]]
+
[[Category:Tcl]]
+
[[Category:String]]
+

Revision as of 18:52, 25 August 2007

solitario con diamante fiorella rubino universita di pisa saxo vts 14 nike bernard tristan palu cardiologia de gregori cara dolce strega www download it poesia don backy hard disk 2 punto elx 2000 escape from castle yandel mascia e fabiani panorama azimut 46 borsa per l ufficio so dimm ddr 333 louis braille accompagnatrici cinesi tapparelle alluminio oro tragico audi caserta bamber stivali cavalli philips tv crt 32 pixel plus 100 hz studios la figlia del mendicante robie williams mp3 audi 1997 meta ati firegl x2 vaio vgns4m bmv m3 imss subdelegacion 5 c e i yetis port 9 la linea nera mamma di villa gogge canon pixma 1500 roccantica zecchino 1997 z 600 new tp key stampante aghi epson zaragoza ristorante dvd gesu di nazareth dizionario medico italiano inglese marco aurelio imperatore romano trium neptune canon vl 20 niki nova piedi nudi sexy sparkle nvidia geforce fx5500 nikon f 50 heroes of the pacific trailer milarepa every morning danze del 700 tintoretto router isdn enervit sport drink microlaser itali kawasaki er la donna della montagna kvm 4 porte cavi vpm110 samsung la principessa delle canarie sindacato inquilini the ones fotos de huanta memory station nascar racing 2001 le armate rosse alla liberazione deuropa mr do siena b b www akela too it lu primo ammore campi di golf il ballo della bussola suficiente diossina a3 color laser nero cucine incontro rivoli lightsaber cibo per animali sesso annunci como alfa 156 sw distinctive lenny craviz lavasciuga ariston aml 129 costantino foto scoppio scala 1 8 modelli auto e moto scaricare sigla di cartoni animati laura pisu santa marina big band bossa nova beti mongo amo il cazzo seychelles invio sms gratis registrazione dubai hotel hp 57 cartuccia fujifilm digital camera compagnia leone cinematografica stelvio massi nights torna nelle voci di corridoio telecamera antifurto bourdaloue louis video gf armadio ufficio marjio barbara bonney se tu non sei con me ml 3320 milanmania videoirc dvd per notebook lalbero di natale hi fi compatto scott bacula news mundance torbida passione canon laser colori dragostea din tin instrumental trium mars f717 sony fotocamere digitali nokia 32 tenda veneziane vesti qualcuno nudo i mate jam forni da incasso microonde auto mg zr panche high power pamela anderson video hard cartuccia iomega rev coppia con cane tomtom go com organizzazione mense ospedaliere per di maglieria dolce gabbana uomo megacock com radioregistratori sony spare me the details coolpix s1 ken ryker finanziamento basso tasso ben 304 benassi sheffield ristorante firenze parigi bryant my scene cerina vincent cinecitta roma www foo fighters com gucci 1651 s pioneer car audio lezioni di politica economica federico sintoamplificatore a v lavoro bolzano codici nagra www warnerhomevideo it sintoamplificatore amplificatore olidata p4 mha wolkswagen polo sportline fanta genitori giochi myoplex mass old ring dvp ns955 don t touch my jeans don t touch my jeans free audio converter rm e ram to mp3 jean claude francoi tassi di interesse bancari vivavoce nokia 6230i alhoa cuffie lettori mp3 panch air terminal senza madre marzo giorgia cpm blue jean monitor lcd spiaggia cavalliere formato pdf lo scrigno orientale come si fa un pompino x files stagione 3 vol 05 cataclisma video baglioni solo all star converse chuck taylor polistirolo milano poeie d amore dottori commercialisti napoli stars nude suonerie polifoniche gratis sony ericsso pf 700 tr perdoname zion y lennox d 407s

Related content:

Implementations

Java

This code removes common symbols and numbers from a string, returning letters only. (Note, not all symbols are included.)

static String lettersOnly(String s) {
   return s.replaceAll("[0-9]|[ !@#\\$%\\^