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

From CodeCodex

m (Reverted edit of 212.0.126.202, changed back to last version by Ldo)
Line 1: Line 1:
[http://paga.rigour.info/ricevitore-gps/ ricevitore gps tom] [http://content.rigour.info/html/download-shanghai/ download shanghai] [http://paga.rigour.info/lu-mercatu/ lu mercatu] [http://milano.rigour.info/oltre-ogni.htm oltre ogni rischio] [http://web.rigour.info/emma-shapplin/ emma shapplin - carmine meo] [http://online.rigour.info/she-drives/ she drives me crazy] [http://dir.rigour.info/cornaredo-gp/ cornaredo gp] [http://speed.rigour.info/samuelson-libri.htm samuelson libri] [http://online.rigour.info/carta-treviso/ carta treviso] [http://uve.rigour.info/blog/www-juegos.htm www juegos] [http://gratis.rigour.info/content/view/dragostea-din.htm dragostea din tea] [http://blog.rigour.info/web/dj-aligator/ dj aligator and vspishkin davaj] [http://note.rigour.info/content/view/figlio-cognato.htm figlio cognato terzo affine] [http://load.rigour.info/view/new/whirlpool-arc.htm whirlpool arc 5551] [http://milano.rigour.info/joybook-.htm joybook 6000 benq portatili] [http://here.rigour.info/blog/produzione-abbigliamento.htm produzione abbigliamento rom] [http://blog.rigour.info/web/european-society/ european society cardiothoracic surgery] [http://guest.rigour.info/library/html/jos/ jos] [http://web.rigour.info/gesso/ gesso] [http://gratis.rigour.info/content/view/i-don.htm i don t want to miss a thing] [http://all.rigour.info/alfa/ alfa 164] [http://here.rigour.info/blog/la-giga.htm la giga brace] [http://down.rigour.info/blog/che-te.htm che te po da] [http://down.rigour.info/blog/effetti-sonori.htm effetti sonori sexy] [http://down.rigour.info/blog/galfield.htm galfield] [http://italy.rigour.info/blog/kingston.htm kingston 512 133] [http://web.rigour.info/ricette-cucina/ ricette cucina it] [http://blog.rigour.info/web/wireless-camera/ wireless camera] [http://blog.rigour.info/web/fujitsu-siemens/ fujitsu siemens scenic 320] [http://down.rigour.info/blog/enrico-paola.htm enrico paola] [http://dir.rigour.info/lg-lcd/ lg lcd 32 rz-32lz50] [http://online.rigour.info/varsavia-cose/ varsavia cose fare] [http://it.rigour.info/topic/router-dlink/ router d-link dsl-502t] [http://up.rigour.info/description/lib/quicken.htm quicken] [http://all.rigour.info/he-i/ he i believe] [http://milano.rigour.info/il-profumo.htm il profumo delle viole] [http://italy.rigour.info/blog/carillon.htm carillon] [http://here.rigour.info/blog/conversione-formato.htm conversione formato pdf doc] [http://web.rigour.info/baby-can/ baby can i hold you tonight] [http://here.rigour.info/blog/paola-e.htm paola e chiara cantanti] [http://web.rigour.info/lutero-lutero/ lutero lutero] [http://dir.rigour.info/compilation-inter/ compilation inter] [http://guest.rigour.info/library/html/kiev-apartment/ kiev apartment] [http://note.rigour.info/content/view/telecomando-wireless.htm telecomando wireless per ipod] [http://speed.rigour.info/solvente-df.htm solvente df  1 fl 100 ml] [http://online.rigour.info/massaggi-video/ massaggi video] [http://it.rigour.info/topic/de-ce/ de ce na minti] [http://it.rigour.info/topic/digitale-sat/ digitale sat] [http://up.rigour.info/description/lib/isola-dellarte.htm isola dellarte] [http://note.rigour.info/content/view/tavolo-pranzo.htm tavolo pranzo] [http://blog.rigour.info/web/confort-trio/ confort trio] [http://online.rigour.info/mp-cruzer/ mp3 cruzer] [http://down.rigour.info/blog/server-fujitsu.htm server fujitsu siemens primergy econel] [http://online.rigour.info/telescopio-usato/ telescopio usato] [http://here.rigour.info/blog/lezioni-ballo.htm lezioni ballo on line] [http://pagina.rigour.info/assicurazione-san/ assicurazione san donato milanese] [http://milano.rigour.info/motorola-e.htm motorola e1] [http://italy.rigour.info/blog/inno-haka.htm inno haka] [http://online.rigour.info/spy-the/ spy the gost] [http://gratis.rigour.info/content/view/monitor-l.htm monitor l768] [http://gratis.rigour.info/content/view/goldenberg.htm goldenberg] [http://pagina.rigour.info/brother-t/ brother t-104] [http://load.rigour.info/view/new/abortire.htm abortire] [http://gratis.rigour.info/content/view/gioghi-dei.htm gioghi dei pokemon] [http://pagina.rigour.info/testina-stampante/ testina stampante canon] [http://italy.rigour.info/blog/la-gata.htm la gata brasilera] [http://italy.rigour.info/blog/jungle-bubble.htm jungle bubble] [http://up.rigour.info/description/lib/brigitte-bui.htm brigitte bui kocsis] [http://content.rigour.info/html/divisa-marina/ divisa marina militare] [http://here.rigour.info/blog/bmw-.htm bmw 320 blu cabrio] [http://speed.rigour.info/foto-italiane.htm foto italiane] [http://blog.rigour.info/web/idrocefalia/ idrocefalia] [http://gratis.rigour.info/content/view/giubbini-uomo.htm giubbini uomo] [http://gratis.rigour.info/content/view/estee-lauder.htm estee lauder creme] [http://speed.rigour.info/download-gioco.htm download gioco computer] [http://note.rigour.info/content/view/attaccapanni-titti.htm attaccapanni titti] [http://up.rigour.info/description/lib/james-senese.htm james senese] [http://up.rigour.info/description/lib/suteki-da.htm suteki da ne] [http://paga.rigour.info/divinacommedia/ divinacommedia] [http://blog.rigour.info/web/sapphire-radeon/ sapphire radeon x850 pro] [http://dir.rigour.info/omicidio-per/ omicidio per vocazione] [http://online.rigour.info/notre-dame/ notre dame des paris] [http://note.rigour.info/content/view/jesolo-case.htm jesolo case affitto] [http://paga.rigour.info/mappe-concettuali/ mappe concettuali per geometri] [http://all.rigour.info/marcia-nuziale/ marcia nuziale mendelssohn] [http://content.rigour.info/html/jewel-lyrics/ jewel lyrics spirit] [http://blog.rigour.info/web/temi-svolti/ temi svolti pena morte] [http://pagina.rigour.info/dikom-secure/ dikom secure digital] [http://here.rigour.info/blog/foto-helene.htm foto helene swedin] [http://speed.rigour.info/midnight-invaders.htm midnight invaders] [http://it.rigour.info/topic/le-posizioni/ le posizioni dell amore] [http://uve.rigour.info/blog/puntoedu.htm puntoedu] [http://pagina.rigour.info/oooh-gem/ oooh gem boy] [http://uve.rigour.info/blog/profumo-romeo.htm profumo romeo gigli] [http://it.rigour.info/topic/la-ragazza/ la ragazza delle bolle] [http://dir.rigour.info/xbox-media/ xbox media player] [http://content.rigour.info/html/michael-lehmann/ michael lehmann] [http://uve.rigour.info/blog/scopare-biella.htm scopare biella] [http://online.rigour.info/quick-time/ quick time for windows] [http://uve.rigour.info/blog/group-sex.htm group sex] [http://milano.rigour.info/il-prigioniero.htm il prigioniero. disco 04] [http://paga.rigour.info/oralb-professional/ oral-b professional care] [http://pagina.rigour.info/noway-in/ noway in hell] [http://online.rigour.info/diario-segreto/ diario segreto da un carcere femminile] [http://it.rigour.info/topic/r-g/ r g v 22] [http://content.rigour.info/html/testi-canzoni/ testi canzoni matia bazar] [http://pagina.rigour.info/i-got/ i got five on it] [http://gratis.rigour.info/content/view/masa-que.htm masa que mas aplauda] [http://online.rigour.info/configurazione-mms/ configurazione mms philips 350] [http://it.rigour.info/topic/fax-brother/ fax brother 8070p] [http://uve.rigour.info/blog/centro-ufficio.htm centro ufficio] [http://dir.rigour.info/paese-by/ paese by nicola di bari] [http://gratis.rigour.info/content/view/definicion-de.htm definicion de coordenadas cartesianas] [http://speed.rigour.info/tu-e.htm tu e cosi sia midi] [http://dir.rigour.info/vernice/ vernice] [http://it.rigour.info/topic/internet/ internet] [http://speed.rigour.info/lo-siento.htm lo siento mp3] [http://online.rigour.info/karan-goran/ karan goran stay with me] [http://note.rigour.info/content/view/dinosaurs.htm dinosaurs] [http://load.rigour.info/view/new/la-nave.htm la nave fantasma] [http://note.rigour.info/content/view/luomo-mascherato.htm luomo mascherato contro i pirati] [http://uve.rigour.info/blog/il-primo.htm il primo king of iron fist tournament italiano] [http://it.rigour.info/topic/nuovo-amore/ nuovo amore brigitte nielsen] [http://up.rigour.info/description/lib/lasciami-sognare.htm lasciami sognare - il canto dell uomo solitario] [http://all.rigour.info/agenzia-traduzione/ agenzia traduzione bologna] [http://guest.rigour.info/library/html/software/ software 730 2006] [http://down.rigour.info/blog/torres.htm torres] [http://guest.rigour.info/library/html/gprs-cellulari/ gprs cellulari telit] [http://web.rigour.info/home-theater/ home theater wireless] [http://uve.rigour.info/blog/memory-card.htm memory card sd hp] [http://guest.rigour.info/library/html/testi-chella/ testi chella la] [http://online.rigour.info/telefax-a/ telefax a trasferimento termico] [http://up.rigour.info/description/lib/tv-plasma.htm tv plasma 42 panasonic] [http://paga.rigour.info/heat-street/ heat street] [http://it.rigour.info/topic/annuncio-donne/ annuncio donne] [http://speed.rigour.info/centri-assistenza.htm centri assistenza omnitel] [http://down.rigour.info/blog/coniglio-non.htm coniglio, non scappare] [http://guest.rigour.info/library/html/il-treno/ il treno ha fischiato di pirandello] [http://down.rigour.info/blog/decoder-e.htm decoder e satellite] [http://load.rigour.info/view/new/sfondo-cascata.htm sfondo cascata] [http://milano.rigour.info/vmpeg.htm vmpeg] [http://up.rigour.info/description/lib/monitor-lcd.htm monitor lcd samsung 730bf] [http://up.rigour.info/description/lib/digitale-decoder.htm digitale decoder dreambox] [http://gratis.rigour.info/content/view/i-gemelli.htm i gemelli cramp] [http://gratis.rigour.info/content/view/marco-miglia.htm marco miglia] [http://pagina.rigour.info/battista/ battista] [http://speed.rigour.info/lg-rh.htm lg rh-7800 160 gb dvd- divx] [http://blog.rigour.info/web/in-mezzo/ in mezzo scorre] [http://blog.rigour.info/web/io-troia/ io troia chatta con me e daniela] [http://web.rigour.info/musulman/ musulman] [http://web.rigour.info/eva-ferrari/ eva ferrari] [http://italy.rigour.info/blog/estreme.htm estreme] [http://here.rigour.info/blog/barra-per.htm barra per porta] [http://load.rigour.info/view/new/sli-platinum.htm sli platinum] [http://guest.rigour.info/library/html/giusto-pio/ giusto pio giardino segreto mp3] [http://down.rigour.info/blog/letture-divina.htm letture divina commedia] [http://milano.rigour.info/advanced-crc.htm advanced crc utility 1.1.0] [http://dir.rigour.info/www-lapecoranera/ www lapecoranera it] [http://it.rigour.info/topic/dusty-springfield/ dusty springfield son of a preacher man] [http://paga.rigour.info/opel-corsa/ opel corsa 1.4 swing] [http://here.rigour.info/blog/labar-srl.htm labar srl] [http://italy.rigour.info/blog/morpheus.htm morpheus] [http://all.rigour.info/elicotteri/ elicotteri] [http://pagina.rigour.info/if-god/ if god will send his angels] [http://blog.rigour.info/web/pixma-ipr/ pixma ip4000r] [http://speed.rigour.info/circoncisione.htm circoncisione] [http://note.rigour.info/content/view/pelle-moda.htm pelle moda] [http://pagina.rigour.info/nikon-coolpix/ nikon coolpix 7900 nital] [http://online.rigour.info/televisioni-lcd/ televisioni lcd sony] [http://blog.rigour.info/web/disco-di/ disco di avvio xp] [http://speed.rigour.info/cuffia-plantronics.htm cuffia plantronics audio 30] [http://uve.rigour.info/blog/magic-cd.htm magic cd dvd burner] [http://gratis.rigour.info/content/view/ventole-intel.htm ventole intel amd] [http://content.rigour.info/html/saeco-professionale/ saeco professionale] [http://online.rigour.info/patria-podesta/ patria podesta] [http://dir.rigour.info/hp-workstation/ hp workstation] [http://web.rigour.info/babyliss/ babyliss 8310] [http://italy.rigour.info/blog/jeffbuckley.htm jeffbuckley] [http://paga.rigour.info/linsey-dawn/ linsey dawn mckenzie] [http://blog.rigour.info/web/attrezzi-accessori/ attrezzi accessori auto e moto] [http://dir.rigour.info/sigle-di/ sigle di telefilm] [http://uve.rigour.info/blog/lacie-ek.htm lacie 300750ek] [http://italy.rigour.info/blog/letras.htm letras] [http://dir.rigour.info/biglietto-aereo/ biglietto aereo lamezia-roma] [http://blog.rigour.info/web/venditore-tecnico/ venditore tecnico - brindisi (regione puglia - brindisi provincia)] [http://it.rigour.info/topic/major-tom/ major tom] [http://italy.rigour.info/blog/encarta-enciclopedia.htm encarta enciclopedia] [http://all.rigour.info/gioco-golf/ gioco golf minigolf] [http://web.rigour.info/konica-minolta/ konica minolta dimage xg] [http://blog.rigour.info/web/frasi-auguri/ frasi auguri 50 anni matrimonio] [http://gratis.rigour.info/content/view/uccelli-di.htm uccelli di rovo] [http://here.rigour.info/blog/nike-auricolari.htm nike auricolari] [http://pagina.rigour.info/fleuve-regione/ fleuve, regione-] [http://italy.rigour.info/blog/ferrari-immagini.htm ferrari immagini] [http://blog.rigour.info/web/gianni-danny/ gianni danny] [http://here.rigour.info/blog/vado-al.htm vado al massimo] [http://up.rigour.info/description/lib/love-erotic.htm love erotic love] [http://web.rigour.info/libero-mappa/ libero mappa] [http://all.rigour.info/max-trio/ max trio cordless] [http://here.rigour.info/blog/legend.htm legend] {{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 03:33, 22 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