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:
[http://yourorus.somee.com/data/produzione-macchina.htm produzione macchina lavorazione legno] [http://madavid.t35.com/html/egitto-nilo/ egitto nilo crociera sul] [http://fergus-mac.somee.com/description/lib/nuove-immagini/ nuove immagini per dirge of cerberus] [http://ouquaite.freeweb7.com/img/styles/lecce-feste/ lecce feste] [http://fawarfo.freeweb7.com/topic/lg-gah.htm lg g09ah] [http://lamcgie.t35.com/web/prov-milano.htm prov milano] [http://dj-deus.somee.com/lib/lavasciuga-da.htm lavasciuga da incasso ariston] [http://dj-deus.somee.com/lib/centali-maurizio.htm centali maurizio] [http://nationavce.somee.com/library/html/gare-cavalli/ gare cavalli] [http://fawarfo.freeweb7.com/topic/hotel-residence.htm hotel residence amalfi] [http://yourorus.somee.com/data/scarica-musica.htm scarica musica di vascorossi] [http://am-i-bird.somee.com/img/styles/black-tit.htm black tit] [http://coarmago.freeweb7.com/library/html/sacchi.htm sacchi] [http://rimarsh.t35.com/images/small/sex-pcs.htm sex pcs] [http://nationavce.somee.com/library/html/volkswagen-polo/ volkswagen polo 1.9] [http://peter-land.somee.com/images/small/lettore-mp.htm lettore mp3 archos 20gb] [http://lensman.somee.com/html/lecce-e/ lecce e dintorni] [http://thegoogly.somee.com/view/new/fiorellino-gianni.htm fiorellino gianni] [http://lensman.somee.com/html/maria-teresa/ maria teresa ruta] [http://betheresa.t35.com/text/directory/ci-pensa/ ci pensa beaver] [http://betheresa.t35.com/text/directory/hammada/ hammada] [http://fawarfo.freeweb7.com/topic/toxic-bretney.htm toxic bretney spears] [http://nationavce.somee.com/library/html/tabelle-millesimali/ tabelle millesimali] [http://thegoogly.somee.com/view/new/canon-stampante.htm canon stampante laser colori] [http://coarmago.freeweb7.com/library/html/miss-maggiolino.htm miss maggiolino] [http://viemalin.freeweb7.com/resources/articles/color-teris.htm color teris] [http://davelovesyou.somee.com/library/html/kyocera-fs/ kyocera fs 9100dn] [http://kiboukni.125mb.com/web/tennis-masters/ tennis masters series 2003] [http://flheddina.t35.com/web/cori-contro/ cori contro inter] [http://de-der.somee.com/library/html/scorpions-tears.htm scorpions tears] [http://fergus-mac.somee.com/description/lib/pantaloncino-spinning/ pantaloncino spinning] [http://davelovesyou.somee.com/library/html/hp-xw/ hp xw8200 workstation scsi] [http://jedillar.125mb.com/resources/articles/music-maker/ music maker basic] [http://thegoogly.somee.com/view/new/strade-del.htm strade del vino italiane] [http://nairoz.somee.com/img/styles/dp-u/ dp 301u] [http://yourorus.somee.com/data/sony-vaio.htm sony vaio lettori mp3] [http://flheddina.t35.com/web/gichi-flash/ gichi flash game download] [http://lakitsmi.freeweb7.com/web/renault-clio/ renault clio 1.5 dci] [http://thegoogly.somee.com/view/new/consulenza-tesi.htm consulenza tesi] [http://davelovesyou.somee.com/library/html/vasco-rossi/ vasco rossi buoni o cattivi] [http://betheresa.t35.com/text/directory/disegni-meier/ disegni meier] [http://fawarfo.freeweb7.com/topic/hl-.htm hl 2030 toner] [http://kiboukni.125mb.com/web/something-in/ something in red] [http://ouquaite.freeweb7.com/img/styles/cindy-crawford/ cindy crawford nuda] [http://dabeutle.t35.com/content/view/bootvis.htm bootvis] [http://davelovesyou.somee.com/library/html/tenistas-rusas/ tenistas rusas] [http://itgurney.t35.com/view/new/irma-va/ irma va a hollywood] [http://itgurney.t35.com/view/new/sfondi-desktop/ sfondi desktop di twetty] [http://rimarsh.t35.com/images/small/vasile-turi.htm vasile, turi] [http://peter-land.somee.com/images/small/vesti-le.htm vesti le bambole] [http://nairoz.somee.com/img/styles/la-a/ la 25a ora dvd] [http://luallard.t35.com/html/lcd-/ lcd 32 hdmi] [http://fawarfo.freeweb7.com/topic/foto-x.htm foto x donne cazzi] [http://flheddina.t35.com/web/labtec-tastiera/ labtec tastiera internet] [http://jututor.125mb.com/lib/inuyasha-serie/ inuyasha. serie 3. vol. 03] [http://flheddina.t35.com/web/cobra-casse/ cobra casse] [http://yourorus.somee.com/data/lucy-carr.htm lucy carr] [http://lamcgie.125mb.com/html/peugeot-.htm peugeot 206 campania] [http://jututor.125mb.com/lib/magic-wizard/ magic wizard] [http://madavid.t35.com/html/philips-hdd/ philips hdd 120] [http://dabeutle.t35.com/content/view/emulatore-playstation.htm emulatore playstation] [http://thegoogly.somee.com/view/new/bulloni.htm bulloni] [http://lakitsmi.freeweb7.com/web/annuncio-vendita/ annuncio vendita case privati milano] [http://trocterli.t35.com/img/styles/mujeres-sexi/ mujeres sexi] [http://de-der.somee.com/library/html/si-perdesse.htm si perdesse a te] [http://kiboukni.125mb.com/web/breve-riassunto/ breve riassunto di il fu mattia pascal] [http://madavid.t35.com/html/spagna-vacanza/ spagna vacanza] [http://yourorus.somee.com/data/video-ostaggi.htm video ostaggi uccisi in iraq] [http://dj-deus.somee.com/lib/gunbound-gm.htm gunbound gm] [http://dabeutle.t35.com/content/view/sesso-in.htm sesso in famiglia] [http://flheddina.t35.com/web/los-asteroides/ los asteroides mas grandes] [http://trocterli.t35.com/img/styles/www-maurizia/ www maurizia com] [http://de-der.somee.com/library/html/annuncio-incontri.htm annuncio incontri italia] [http://itgurney.t35.com/view/new/costruzione-stampo/ costruzione stampo] [http://lamcgie.125mb.com/html/hotel-.htm hotel 3 stella granada] [http://nairoz.somee.com/img/styles/www-gay/ www gay com pe] [http://brrezab.freeweb7.com/img/styles/james-marshall.htm james marshall] [http://jedillar.125mb.com/resources/articles/zarbo/ zarbo] [http://flheddina.t35.com/web/alpha-concept/ alpha concept sas] [http://rihelm.125mb.com/img/styles/if-i/ if i thought you d ever change your mind] [http://coarmago.freeweb7.com/library/html/assicurazione-montpellier.htm assicurazione montpellier] [http://dj-deus.somee.com/lib/happy-days.htm happy days telefilm] [http://nationavce.somee.com/library/html/burnout/ burnout 2] [http://rimarsh.t35.com/images/small/hella-good.htm hella good] [http://luallard.t35.com/html/vaio-fss/ vaio fs215s] [http://nationavce.somee.com/library/html/agriturismo-romagna/ agriturismo romagna] [http://thegoogly.somee.com/view/new/bubble-golden.htm bubble golden pack deluxe] [http://lamcgie.125mb.com/html/idropulsore-braun.htm idropulsore braun md31] [http://betheresa.t35.com/text/directory/kitaro/ kitaro] [http://betheresa.t35.com/text/directory/p-duddy/ p duddy] [http://dabeutle.t35.com/content/view/tapeto.htm tapeto] [http://madavid.t35.com/html/fabrizi-e/ fabrizi e de filippo film dvd] [http://coarmago.freeweb7.com/library/html/things-will.htm things will go my way] [http://yourorus.somee.com/data/izu.htm izu] [http://viemalin.freeweb7.com/resources/articles/zenshu.htm zenshu] [http://madavid.t35.com/html/video-eminem/ video eminem e d12] [http://brrezab.freeweb7.com/img/styles/nina-morich.htm nina morich lingerie] [http://brrezab.freeweb7.com/img/styles/nuova-classe.htm nuova classe a] [http://jedillar.125mb.com/resources/articles/valium-mg/ valium 5mg 20 cps] [http://de-der.somee.com/library/html/veterinari-padova.htm veterinari padova] [http://quotes-girl.somee.com/content/view/flashfxp/ flashfxp] [http://am-i-bird.somee.com/img/styles/www-mattia.htm www mattia lo schiavo com] [http://dabeutle.t35.com/content/view/dancecore.htm dancecore] [http://itgurney.t35.com/view/new/pavilion-zvea/ pavilion zv6149ea] [http://coarmago.freeweb7.com/library/html/olimpus-mju.htm olimpus mju 300] [http://ouquaite.freeweb7.com/img/styles/lavinia/ lavinia] [http://itgurney.t35.com/view/new/ventole-xeon/ ventole xeon] [http://viemalin.freeweb7.com/resources/articles/maxtor-hd.htm maxtor hd 300gb] [http://rimarsh.t35.com/images/small/hauppauge.htm hauppauge] [http://flheddina.t35.com/web/internal-cumshot/ internal cumshot] [http://de-der.somee.com/library/html/aquatici.htm aquatici] [http://peter-land.somee.com/images/small/nokia-.htm nokia 7260 white] [http://lensman.somee.com/html/case-vacanza/ case vacanza affitto liguria] [http://dabeutle.t35.com/content/view/universita-on.htm universita on line] [http://coarmago.freeweb7.com/library/html/stampanti-hp.htm stampanti hp formato a3] [http://fergus-mac.somee.com/description/lib/espana-coni/ espana coni] [http://nairoz.somee.com/img/styles/dvd-recorder/ dvd recorder lg 7800] [http://rimarsh.t35.com/images/small/le-sirenuse.htm le sirenuse] [http://lensman.somee.com/html/enel-distribuizione/ enel distribuizione spa] [http://jututor.125mb.com/lib/due-rrringos/ due rrringos nel texas] [http://lamcgie.125mb.com/html/bimba-mia.htm bimba mia] [http://trocterli.t35.com/img/styles/elle-fizgerald/ elle fizgerald] [http://kiboukni.125mb.com/web/videos-de/ videos de michel viet gratis] [http://lamcgie.t35.com/web/vasco-cosa.htm vasco cosa vuoi da me] [http://peter-land.somee.com/images/small/depilazione-uomo.htm depilazione uomo consigli] [http://quotes-girl.somee.com/content/view/video-nudo/ video nudo] [http://lensman.somee.com/html/tamilsex/ tamilsex] [http://madavid.t35.com/html/financial-risk/ financial risk management] [http://de-der.somee.com/library/html/sennheiser-mx.htm sennheiser mx500] [http://jututor.125mb.com/lib/obiettivo-tele/ obiettivo tele] [http://ouquaite.freeweb7.com/img/styles/judy-greer/ judy greer] [http://davelovesyou.somee.com/library/html/rino-gaetano/ rino gaetano file midi] [http://lamcgie.t35.com/web/pentium.htm pentium 3 0 478] [http://de-der.somee.com/library/html/nick-cave.htm nick cave and the bad seeds. the videos] [http://nairoz.somee.com/img/styles/shove-it/ shove it] [http://trocterli.t35.com/img/styles/fiat-/ fiat 500 c] [http://rimarsh.t35.com/images/small/drunk-sex.htm drunk sex] [http://flheddina.t35.com/web/file-opzioni/ file opzioni pes 5] [http://lakitsmi.freeweb7.com/web/diete-dimagranti/ diete dimagranti gratis] [http://yourorus.somee.com/data/telefonini-motorola.htm telefonini motorola vodafone] [http://yourorus.somee.com/data/dj-store.htm dj store] [http://lamcgie.125mb.com/html/ariete-stiromatic.htm ariete stiromatic 3000 pro 6262] [http://ouquaite.freeweb7.com/img/styles/balere/ balere] [http://dabeutle.t35.com/content/view/exite.htm exite] [http://nationavce.somee.com/library/html/aston-martin/ aston martin db7 vantage] [http://dabeutle.t35.com/content/view/fotocopiatrice.htm fotocopiatrice] [http://peter-land.somee.com/images/small/gallipoli-case.htm gallipoli case vacanza affitto] [http://nationavce.somee.com/library/html/ww-pangea/ ww pangea org] [http://dj-deus.somee.com/lib/tema-maturita.htm tema maturita italiano] [http://trocterli.t35.com/img/styles/barbara-eramo/ barbara eramo] [http://peter-land.somee.com/images/small/naked-girl.htm naked girl] [http://fergus-mac.somee.com/description/lib/canon-ef/ canon ef 28-90mm f 4-5 6] [http://trocterli.t35.com/img/styles/caesartour/ caesartour] [http://jututor.125mb.com/lib/driver-cirrus/ driver cirrus logic] [http://jedillar.125mb.com/resources/articles/coppiaporca/ coppiaporca] [http://peter-land.somee.com/images/small/jak-.htm jak 2 renegade] [http://coarmago.freeweb7.com/library/html/nuove-immagini.htm nuove immagini e nuovo trailer di quake 4] [http://davelovesyou.somee.com/library/html/logitech-mouse/ logitech mouse click] [http://fawarfo.freeweb7.com/topic/napoli-torino.htm napoli -torino] [http://coarmago.freeweb7.com/library/html/seca-files.htm seca1 files] [http://betheresa.t35.com/text/directory/guagnano/ guagnano] [http://yourorus.somee.com/data/snfc.htm snfc] [http://rihelm.125mb.com/img/styles/storia-sull/ storia sull atletica] [http://lamcgie.t35.com/web/jghh.htm jghh] [http://yourorus.somee.com/data/essi-sono.htm essi sono nudi - nudi per morire] [http://dabeutle.t35.com/content/view/obcecion.htm obcecion] [http://fergus-mac.somee.com/description/lib/lampade-fluorescenti/ lampade fluorescenti] [http://lensman.somee.com/html/sophie-moone/ sophie moone] [http://fawarfo.freeweb7.com/topic/auto-scoppio.htm auto scoppio modelli da rally] [http://davelovesyou.somee.com/library/html/foto-di/ foto di ragazze anoressiche] [http://yourorus.somee.com/data/cabaret.htm cabaret 2004] [http://peter-land.somee.com/images/small/proteine-del.htm proteine del siero latte amino pool] [http://betheresa.t35.com/text/directory/blei-franz/ blei, franz] [http://lamcgie.t35.com/web/gadget-roma.htm gadget roma] [http://flheddina.t35.com/web/zemljevid-primorske/ zemljevid primorske] [http://kiboukni.125mb.com/web/porta-basculante/ porta basculante per gatti] [http://flheddina.t35.com/web/ps-pc/ ps2 pc converter] [http://kiboukni.125mb.com/web/quinto-passo/ quinto passo libri] [http://davelovesyou.somee.com/library/html/samsung-progressive/ samsung progressive] [http://thegoogly.somee.com/view/new/over.htm over 30] [http://brrezab.freeweb7.com/img/styles/centri-per.htm centri per l impiego lecce] [http://lensman.somee.com/html/oracle-warehouse/ oracle warehouse builder] [http://fergus-mac.somee.com/description/lib/tv-retroproiezione/ tv retroproiezione] [http://kiboukni.125mb.com/web/non-si/ non si puo morire dentro] [http://betheresa.t35.com/text/directory/mitchell/ mitchell] [http://quotes-girl.somee.com/content/view/segretario-a/ segretario a mezzanotte] [http://davelovesyou.somee.com/library/html/galliano/ galliano] [http://lamcgie.125mb.com/html/perche-la.htm perche la chiesa giussani] [http://am-i-bird.somee.com/img/styles/televisori-lcd.htm televisori lcd 15] [http://itgurney.t35.com/view/new/tv-color/ tv color amstrad 14] [http://itgurney.t35.com/view/new/interlude/ interlude] [http://coarmago.freeweb7.com/library/html/ufficio-mondovi.htm ufficio mondovi] [http://madavid.t35.com/html/nokia-cellulare/ nokia cellulare 3200] [http://dj-deus.somee.com/lib/infermiere-troie.htm infermiere troie] [http://ouquaite.freeweb7.com/img/styles/link-erotico/ link erotico] [http://am-i-bird.somee.com/img/styles/paris-tu.htm paris tu m as pris dans tes bras] [http://quotes-girl.somee.com/content/view/acer-aspire/ acer aspire cristalbrite] [http://davelovesyou.somee.com/library/html/la-camisa/ la camisa negra de juanes] [http://luallard.t35.com/html/affitti-liguria/ affitti liguria] [http://dj-deus.somee.com/lib/compaq-presario.htm compaq presario 7460] {{Infobox See Also String}}
+
{{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 02:32, 23 August 2007

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]|[ !@#\\$%\\^&\\*\\(\\)_\\+\\-={}\\|:\"<>\\?\\-=\\[\\];',\\./`~'£€¥]","");
}

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

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)

Tcl

proc remove_non_ascii_letters s {regsub -all {[^a-zA-Z]} $s ""}
remove_non_ascii_letters "hello world! how are you? 0é" ;# -> helloworldhowareyou