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

From CodeCodex

m (Reverted edit of 62.231.243.136, changed back to last version by Daxim)
Line 1: Line 1:
{{Infobox See Also String}}
+
[http://tizolaa.ifrance.com/web/colores/ colores] [http://highbulp.ifrance.com/images/small/interflora-chieti/ interflora chieti] [http://oiyaoi.ifrance.com/images/small/croma-latina/ croma latina lyrics] [http://lovereceier.ifrance.com/lib/microsoft-offi.htm microsoft offi] [http://broadwaylili.ifrance.com/content/view/pile-aa.htm pile aa ricaricabili] [http://tizolaa.ifrance.com/web/dio-dei/ dio dei boschi] [http://singaporepets.ifrance.com/library/html/ricetrasmittenti.htm ricetrasmittenti] [http://jdawsona.ifrance.com/data/router-us/ router us robotics wireless] [http://oiyaoi.ifrance.com/images/small/pentium-/ pentium 4 3 8 ghz socket 775] [http://broadwaylili.ifrance.com/content/view/pianoteacher.htm pianoteacher] [http://broadwaylili.ifrance.com/content/view/divx-dvp.htm divx dvp630] [http://toofarfrommaybe.ifrance.com/view/new/yves-saint/ yves saint laurent cinema] [http://girlwho-is.ifrance.com/img/styles/new-beetle.htm new beetle como] [http://noxuhax.ifrance.com/content/view/lui.htm lui] [http://oiyaoi.ifrance.com/images/small/pierobon/ pierobon] [http://kalian42.ifrance.com/text/directory/aramo-pasquale/ aramo pasquale] [http://deviantrus.ifrance.com/topic/lettino-da/ lettino da massaggi] [http://deviantrus.ifrance.com/topic/chicco-rodeo/ chicco rodeo] [http://jdawsona.ifrance.com/data/samsung/ samsung 335] [http://igaros.ifrance.com/lib/germe-di/ germe di grano] [http://tizolaa.ifrance.com/web/culi-da/ culi da sballo] [http://highbulp.ifrance.com/images/small/strumien/ strumien] [http://igaros.ifrance.com/lib/albergo-lido/ albergo lido jesolo] [http://lovereceier.ifrance.com/lib/linfoma.htm linfoma] [http://toofarfrommaybe.ifrance.com/view/new/athlon/ athlon64 3700] [http://demurediablo.ifrance.com/library/html/monna-lisa/ monna lisa] [http://toofarfrommaybe.ifrance.com/view/new/repubblica-ceca/ repubblica ceca hotel] [http://deviantrus.ifrance.com/topic/biotera/ biotera] [http://kalian42.ifrance.com/text/directory/palmari-gps/ palmari gps phone] [http://noxuhax.ifrance.com/content/view/le-avventure.htm le avventure di frank] [http://broadwaylili.ifrance.com/content/view/lunar-silver.htm lunar silver star] [http://kalian42.ifrance.com/text/directory/kit-car/ kit car] [http://tat-ooin.ifrance.com/resources/articles/guetar.htm guetar] [http://deviantrus.ifrance.com/topic/ammortizzatori-sociali/ ammortizzatori sociali] [http://demurediablo.ifrance.com/library/html/bestemmi/ bestemmi] [http://tat-ooin.ifrance.com/resources/articles/canzoni-italiane.htm canzoni italiane] [http://deviantrus.ifrance.com/topic/dv-in/ dv in] [http://broadwaylili.ifrance.com/content/view/matiz-star.htm matiz star] [http://speedofsoun.ifrance.com/text/directory/fiabilandia.htm fiabilandia] [http://lovereceier.ifrance.com/lib/partenze-per.htm partenze per milano] [http://akmokanzen.ifrance.com/images/small/acer-n.htm acer n50 premium] [http://singaporepets.ifrance.com/library/html/adsl-pppoa.htm adsl pppoa modem] [http://jdawsona.ifrance.com/data/voce-me/ voce me apareceu video] [http://toofarfrommaybe.ifrance.com/view/new/hotel-lungomare/ hotel lungomare a cattolica] [http://highbulp.ifrance.com/images/small/audi-sicilia/ audi sicilia] [http://oiyaoi.ifrance.com/images/small/wt/ wt 615] [http://tat-ooin.ifrance.com/resources/articles/hello-evanescence.htm hello evanescence] [http://voltia.ifrance.com/content/view/www-latin.htm www latin chat] [http://voltia.ifrance.com/content/view/hdv-sony.htm hdv sony] [http://jdawsona.ifrance.com/data/batamn/ batamn 3] [http://broadwaylili.ifrance.com/content/view/eusebio-robledo.htm eusebio robledo colombiano] [http://demurediablo.ifrance.com/library/html/carlo-scarpa/ carlo scarpa] [http://demurediablo.ifrance.com/library/html/le-/ le  puni] [http://lovereceier.ifrance.com/lib/un-poliziotto.htm un poliziotto scomodo] [http://girlwho-is.ifrance.com/img/styles/acer-aspire.htm acer aspire rc810] [http://speedofsoun.ifrance.com/text/directory/codici-sblocco.htm codici sblocco autoradio] [http://broadwaylili.ifrance.com/content/view/acchiappa-te.htm acchiappa te] [http://speedofsoun.ifrance.com/text/directory/la-vedova.htm la vedova non veste di nero] [http://toofarfrommaybe.ifrance.com/view/new/marco-masini/ marco masini il giorno di natale] [http://singaporepets.ifrance.com/library/html/megan-calendario.htm megan calendario 2001] [http://singaporepets.ifrance.com/library/html/alzara.htm alzara] [http://akmokanzen.ifrance.com/images/small/dvd-r.htm dvd r vergini verbatim] [http://highbulp.ifrance.com/images/small/lamante-del/ lamante del re] [http://tat-ooin.ifrance.com/resources/articles/ludwig-van.htm ludwig van beethoven. symphony no. 9 corale] [http://lovereceier.ifrance.com/lib/campeggio-ischia.htm campeggio ischia] [http://highbulp.ifrance.com/images/small/sborrate-trans/ sborrate trans] [http://girlwho-is.ifra
==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===
+
<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 23:07, 19 August 2007

colores interflora chieti croma latina lyrics microsoft offi pile aa ricaricabili dio dei boschi ricetrasmittenti router us robotics wireless pentium 4 3 8 ghz socket 775 pianoteacher divx dvp630 yves saint laurent cinema new beetle como lui pierobon aramo pasquale lettino da massaggi chicco rodeo samsung 335 germe di grano culi da sballo strumien albergo lido jesolo linfoma athlon64 3700 monna lisa repubblica ceca hotel biotera palmari gps phone le avventure di frank lunar silver star kit car guetar ammortizzatori sociali bestemmi canzoni italiane dv in matiz star fiabilandia partenze per milano acer n50 premium adsl pppoa modem voce me apareceu video hotel lungomare a cattolica audi sicilia wt 615 hello evanescence www latin chat hdv sony batamn 3 eusebio robledo colombiano carlo scarpa le puni un poliziotto scomodo acer aspire rc810 codici sblocco autoradio acchiappa te la vedova non veste di nero marco masini il giorno di natale megan calendario 2001 alzara dvd r vergini verbatim lamante del re ludwig van beethoven. symphony no. 9 corale campeggio ischia sborrate trans [http://girlwho-is.ifra