Archivo de la etiqueta: expresion regular

Expresiones regulares (regex)

El trabajo con expresiones regulares es algo poco conocido por los programadores aficionados. Aquí comento algunos enlaces y ejemplos para ilustrar su utilidad.

En la facultad, este timo de cosas lo veíamos en una asignatura llamada “Lenguajes, Gramáticas y Autómatas”, asignatura bastante complicada a la vez que interesante (aunque de esto último me di cuenta más tarde).

Podríamos decir que las expresiones regulares son fórmulas que actúan como una regla o patrón para definir palabras válidas. Este concepto es muy potente, sobre todo si quieres diseñar un compilador o un intérprete de un lenguaje… pero me estoy desviando, vayamos a la “praxis”.

Está demás que me ponga ahora a comentar todos los pormenores de una expresión regular, para ello os remito unos enlaces que lo aclaran bastante:

http://www.regular-expressions.info (en Inglés)
http://es.wikipedia.org/wiki/Expresi%C3%B3n_regular

Si queréis usar una pequeña utilidad para verificar al momento si vuestra expresión regular hace lo que vosotros creéis que hace la que sigue es una muy buena herramienta (a mí me ha ayudado mucho):

http://regexpal.com/

Un par de ejemplos sencillos.

Antes de pasar a los ejemplos es importante que aclaremos que la expresión regular no hace nada especial si hablamos de programación, sólo establece un patrón que permite identificar secuencias válidas. Es decir, identificamos elementos en cadenas de caracteres, lo que hagamos con ellos depende del lenguaje de programación y de los métodos o instrucciones de programación. También advierto que no todos los lenguajes de programación permiten detección de patrones mediante expresiones regulares.

EJEMPLO 1: Eliminar los espacios sobrantes alrededor de una cadena de caracteres.

Una práctica habitual (muy recomendada desde mi punto de vista) es la eliminación de blancos en los extremos de una cadena antes de procesarla. Esta función es conocida como “trimming” (en inglés, el verbo “to trim” significa “recortar”).

Para obtener la cadena válida, sin blancos molestos, se puede aplicar una expresión regular que “extrae” los caracteres en blanco al inicio y al final de la cadena. Detectados estos espacios sobrantes sólo hemos de sustituirlos por la cadena vacía y obtendremos una cadena de caracteres donde ya no tenemos estos espacios sobrantes a izquierda y derecha.

La expresión regular que lo lleva a cabo es:

^[ \s]+|[ \s]+$

Por supuesto, hay otras variantes, pero jamás había visto una tan sencilla, es, sin duda, la más elegante. Esto viene a leerse algo así como: me quedo con todo hasta encontrar algo diferente a un separador o me quedo con todos los separadores en blanco del final.

Lo del $ era lo que yo no sabía para decir eso “del final de cadena”. También he de decir que con el carácter “\s” no sólo identificamos espacios en blanco, sino cualquier caracter espaciador, esto incluye tabuladores y creo que también avances de línea y retornos de carro, aunque yo sólo he probado con espacios.

EJEMPLO 2: Detección de etiquetas HTML.

Otro caso típico. Imaginad que hemos de mostrar un texto pero éste se haya mezclado con código HTML. El modo de “limpiar” este código es eliminar los textos incluidos en las etiquetas HTML, es decir, todo lo que se encuentre entre el carácter < y el carácter >.

¿Cómo lo hacemos? La expresión regular que detecta las etiquetas HTML sería la siguiente:

<[^>]*>

La descripción textual sería algo así como el caracter < seguido de todo lo que sea excepto el caracter > y todo ello seguido del caracter >.

Sigo fascinado con la elegancia del patrón. Además tengamos en cuenta que este patrón es válido para etiquetas de apertura de HTML y etiquetas de cierre.

Conclusiones

Recordad que las expresiones regulares proporcionan una herramienta muy potente para el tratamiento de cadenas pero, debido a su potencia, en manos inexpertas puede ocasionar grandes desastres que son muy graciosos cuando no le pasan a uno mismo.

He decidido plasmar en el blog esta pequeña pero útil información porque no es la primera vez que la busco, así quedará anotada para siempre. El hecho de anotarla también ha estado influenciado por el sitio en el que la he hallado (http://www.regular-expressions.info), que he decidido incluirlo en mi lista de recursos. Jamás había encontrado un sitio tan claro hablando de expresiones regulares.

Llevad cuidado y haced esto siempre bajo la supervisión de un adulto, computacionalmente hablando, claro ;-)

When Brady’s four game suspension for his alleged involvement in “Deflate gate” was overturned on Sept. 3, Trump was quick to align himself with the NFL star, who he called an “honorable man.”In August, Trump criticized NFL Commissioner Roger Goodell decision to suspend Brady in the first place.”I think it’s ridiculous the way they’ve treated him,” Trump said during a FOX Business Channel interview. “He’s a friend of mine, he’s a great friend of mine, he’s a great guy, and I think it’s ridiculous the way they’ve treated him. To spend $10 cheap jerseys million in legal fees, and now it’s probably higher than that, it’s crazy. He’s a great star. They ought to go back to playing football. This country has bigger problems.”IntroThis hub is going to talk about, first off exactly what Madden Ultimate team is for those of you who haven’t tried this in Madden 12 or prior, or are experimenting with this game mode. I will also talk about strategies on how to win games, get coins, and overall build that team that you want. Please feel free to comment below, or if need be you can message me in game on Xbox 360. My gamer tag is MKS JohnR space between MKS and johnR. MUTOpen Microsoft Publisher. In the “New Publication” task pane, expand “Blank Publications” by clicking the arrow to its left. Double click “Business Cards.” It will appear that one business card opens in the window. However, the changes you make to this business card will create an entire sheet of the same cards.Historically, about 75 percent of overtime games have been decided by field goals, while the other quarter has been sealed with touchdowns. This year’s contests have mostly mirrored this trend; ten games have been won by field goals, three by touchdowns, and three by cheap oakleys turnovers, a new outcome under the current rules.And when Australians sat down in front of their televisions most nights last week, it was not the likelihood of an invasion of Iraq that preoccupied news broadcasters but the state of Shane Warne’s shoulder. This is the agenda set by a media obsessed with sport and the ratings fake oakleys it brings.Let’s not beat around the bush. ray bans ale Last year was an absolute disaster for Luck. After breaking out at an elite level in 2014, a year in which he threw for 4,761 yards, 40 touchdowns and 16 interceptions, the Colts’ franchise quarterback played just seven games and threw 15 touchdowns and 12 interceptions. In those seven games, his rating was 74.9, compared to 2014’s 96.5 mark. It was clear that he hockey jerseys was playing at less than 100 percent cheap jerseys for at least a couple of his seven starts, but nonetheless, he struggled. In order to put more of the emphasis in his hands this season, the Colts have moved from a two wide receiver, two tight end primary formation on offense (likely due to the departure of tight end Coby Fleener) to a three wide receiver, one tight end look. This will allow Luck to spread the ball to more elusive and more dangerous playmakers and will place much of the offensive burden on his shoulders and away from veteran Frank Gore and the running game. oakley outlet That being said, look for numbers like 2014 to become a reality once again for Luck, who knows he needs to live up to his massive contract and perform like an elite quarterback for his team to win games.

side effects of viagra viagra generic cialis vs viagra cialis dosage canada cialis amoxil 500 mg otc viagra female viagra pills generic cialis tadalafil amoxicillin medscape online viagra viagra without a doctor prescription usa cialis copay card cialis voucher amox clav 875-125 viagra pharmacy daily cialis cialis samples overnight amoxicilin generic viagra amoxicillin 875 mg levitra vs viagra cialis 5 mg liquid cialis cialis 30 day trial coupon what is cialis amoxicillin/clavulanic acid walgreens viagra substitute cialis trial what is anoxia natural viagra stendra vs viagra cialis cheap viagra side effect of amoxicillin cialis sample side effects of amoxicillin viagra dosage cialis pricing axoloti mexican salamander cialis dosage strengths viagra coupons 75 off cheap viagra amoxil dosage augmentin dosage generic cialis at walmart buy viagra online how much does viagra cost viagra cost what is amoxicillin used for how much does cialis cost cialis reviews cialis 20mg directions how to take cialis amoxicillan amoxicillin trihydrate 500mg healthy man viagra cialis for sale trimox cialis pills amox clav 875 amoxin amox amoxicillin 500 amoxicillin side effects amoxicillin side effects in men generic for cialis anadrol herbal viagra amoxicillin cialis generic viagra ingredients cilias cialis or viagra viagra pills viagra pills for sale augmentin 500 viagra dose viagra 100mg price walmart cialis coupon amoxicillin dosage best price viagra cialis for bph cost of cialis cialis patent expiration viagra online online cialis where to buy viagra viagra side effects free viagra viagra on line order online viagra pfizer viagra discount viagra cialis without a doctor’s prescription sildenafil vs viagra amox-clav 875-125 mg tablet axolot generic viagra 100mg cost of viagra amoxcillin viagra price what is amoxicillin cialis 30 day sample viagra substitute viagra cialis amoxil how does cialis work cialis website cialis from canada is viagra federally funded axolotls cvs pharmacy viagra coupons moxil what is viagra cialis discount amoxicillin rash cialis medication amoxycillin viagra government funded 200 cialis coupon amoxicillin and clavulanate potassium 875 125 viagra sex is viagra covered by insurance amoxicillin uti cialis coupons 2017 amoxicillin uses amoxicillin 500mg axolotyl viagra from canada cialis daily cialis on line cialis 5mg daily cialis pills for sale cialis canadian pharmacy buy cialis non prescribed viagra cialis patent expiration date extended cialis coupons printable amoxi cialis coupon print cialis prices amoxicillin clavulanate free cialis when will cialis go generic amox/k clav 875-125 viagra on line no prec tamoxifen inexpensive viagra pills viamedic cialis cialis 20 mg cialis coupons is viagra government funded in america axolotl cialis tadalafil viagra from amazon cialis samples viagra coupons from pfizer cheap cialis trial viagra sample does viagra work viagra prices without insurance viagra pill amoxicillin 500 mg for sinus infection cialis online amovil viagra single packs cost cialis free trial viagra best price viagra coupon is viagra government funded viagra for sale natural viagra alternatives that work cialis 5mg cialis canada amoxillin amoxicillin 500 mg and alcohol amoxicillin for cats amoxicillin tablets amoxicillin side effects in women canadian viagra cialis dosage recommendations amoxicillin 500mg capsules side effects of cialis cealis cialis vs viagra amoxicillian cialis for daily use cialis for men cialas viagra girls cialis alternative buy viagra pfizer viagra coupons viagra without prescription amoxicilina female viagra viagra savings offer generic for viagra cialis generic tadalafil buy cialis online canadian cialis axlotl cialis for women how long does viagra last viagra government funding cialis coupon 20 mg amoxicillin 500 mg cialis 10 mg viagra canada cialis pharmacy prices viagra prices viagra vs cialis cialis or viagra sex viagra for women cialis generic availability mexican walking fish amox-clav 875-125 mg cialis savings card cialis cialis price sophia viagra utilisation viagra price cialis axoltl canada viagra viagra for women viagra coupons cialis testimonials cialis coupons from manufacturer augmentin 875-125 augmentin drug class discount cialis generic cialis amoxicillin 250mg lowest cialis prices over the counter viagra cialis professional viagra without a doctor prescription viagra 100mg tablets retail price what does viagra do cialis otc viagra patent expiration generic viagra available in usa cialis side effects women viagra amoxidal dosage of amoxicillin xolotl side effects of amoxicillin 500 mg cialis patent expiration 2017 viagra activate is viagra funded by government cialis 20mg viagra vs cialis erectile dysfunction cialis amoxacilin how does viagra work viagra samples wholesale cialis viagra costs viagra single packs cialis effects amox-clav 875-125 does the government fund viagra viagra porn viagra vs cialis vs levitra cyalis amoxicillin dosing viagra alternatives revatio vs viagra cialis cost

finasteride long term effects cialis tadalafil is lexapro a controlled substance azithromycin pediatric dosing acyclovir dose what is acyclovir used for side effects of acyclovir is azithromycin penicillin how long for lexapro to work canadian cialis cipro for uti escitalopram 20 mg ciprofloxacin 500 mg tabletten cialis cheap tamoxifen bijwerkingen azithromycin liquid viagra pills tamoxifen langzeitfolgen sex viagra for women escitalopram nebenwirkungen tamoxifen citrate viagra tablets azithromycin 500 levitra vs viagra for hardness discount viagra viagra receptfritt ciprofloxacin coverage escitalopram effets secondaires celexa vs lexapro side effects of lexapro 10 mg stopping lexapro viagra canada viagra pill cialis patent expiration date extended azithromycin for uti vardenafil 20mg ciprofloxacin 500 mg for urinary tract infection wholesale cialis what does ciprofloxacin treat tamoxifen cialis savings card buy levitra online viagra cost azithromycin zovirax lexapro para que sirve viagra tesco what does finasteride do viagra substitute how long does viagra last finasteride for hair loss female viagra ciprofloxacin cialis cialis discount generic levitra vardenafil 20mg azithromycin and alcohol lexapro dosages women viagra finasteride effets secondaires cost of viagra viagra 100 acyclovir dosing viagra sans ordonnance lexapro cialis voucher cialis 5mg daily levitra azithromycin class buy viagra cialis samples finasteride 5mg canadian viagra cialis website azithromycin drug class viagra vs cialis vs levitra ciprofloxacin 500mg antibiotics zovirax cream acyclovir 400 mg viagra generic finasteride and enlarged prostate buy generic levitra cialis cost cialis from canada lexapro vs zoloft ciprofloxacin hcl 500 mg finasteride for women cialis copay card cialas canada cialis cialis 30 day trial coupon what is finasteride levitra without a doctor prescription cialis without a doctor’s prescription ciprofloxacin hcl tamoxifen and foods to avoid cialis samples overnight what is lexapro when will cialis go generic what is cialis side effects of ciprofloxacin cialis effects first few days on lexapro tamoxifen side effects in women over 55 cyalis cialis 10 mg lexapro medication viagra kaufen ciprofloxacin dosierung finasteride reviews escitalopram oxalate cipro drug class side effects of viagra cipro side effects in elderly cilias cialis daily what is lexapro for how does acyclovir work finasteride 5mg side effects propecia side effects wellbutrin and lexapro cialis generic cialis dosage strengths how to get off lexapro ciprofloxacin 500 mg does lexapro cause weight gain is azithromycin discount cialis lexapro and weight gain cealis viagra alternative lexapro 5mg ciprofloxacin 500 azithromycin three times a week azithromycin side effects viagra for sale uk finasteride dosage how to wean off lexapro without withdrawals finasteride 5mg tab liquid cialis viagra from canada cialis generic tadalafil generic levitra zithromax dosage cialis online generic cialis cialis 20mg cialis coupons printable azithromycin for pneumonia is tamoxifen chemotherapy cialis canada zovirax ointment how to wean off lexapro cost of cialis cialis coupon 20 mg viagra 100mg tablets retail price how to take cialis viagra for men cialis generic availability cialis 20mg directions cialis patent expiration 2017 finasteride tablets cipro antibiotic escitalopram 10 mg para que sirve lexapro and weight gain in women utilisation viagra lexapro generic levitra erfahrungen viagra on line online cialis what is ciprofloxacin prescribed for ciprofloxacin 250mg ciprofloxacin side effects after age 60 antibiotic ciprofloxacin ciprofloxacin bnf viagra coupons azithromycine 250 mg levitra coupons ciprofloxacin dose what is viagra cialis alternative azithromycin pregnancy natural viagra finasteride 5mg side effects mayo clinic viagra wikipedia levitra prezzo in farmacia lexapro 10 mg ciprofloxacin 500mg tablets azithromycin 500mg cialis pricing viagra en ligne livraison 24h generic for lexapro azithromycin vs erythromycin finasteride 5 mg sophia viagra generic viagra ciprofloxacin drops viagra 50mg what is acyclovir levitra rezeptfrei deutschland azithromycine 200 cialis coupon cialis 5mg tamoxifen nebenwirkungen cipro antibiotics lexapro and weight loss azithromycin dosage viagra medicine lexapro vs wellbutrin cialis coupons 2017 cialis pills for sale erectile dysfunction cialis levitra generic side effects of tamoxifen lexapro withdrawal symptoms how does cialis work levitra dosage lexapro 20mg viagra online viagra bestellen canada viagra finasteride hair loss weaning off lexapro what is ciprofloxacin used for azithromycin 250 mg ciprofloxacin drug class viagra for sale lexapro withdrawal finasteride medication finasteride efectos secundarios viagra wiki ciprofloxacin side effects in women is ciprofloxacin a penicillin lexapro and wellbutrin combination therapy cipro withdrawal from lexapro azithromycin 500 erfahrungen viagra natural effects of stopping finasteride levitra vs viagra what is azithromycin used for ciprofloxacin spc ciprofloxacin nebenwirkungen viagra activate viagra 100mg lexapro overdose lexapro manufacturer website what is tamoxifen cheap cialis acyclovir dosage side effects of azithromycin viagra generico ciprofloxacin eye drops lexapro dosing levitra 20 mg cost walmart lexapro generic name over the counter viagra side effects lexapro azithromycin without a doctor’s prescription finasteride results lexapro side effects in women best price viagra cialis free trial cialis trial lexapro side effects men herbal viagra nolvadex cialis dosage recommendations side effects of finasteride azithromycin 500 mg viagra nebenwirkungen lexapro vs celexa lexapro side effects how long for azithromycin to take effect acyclovir 800mg what is finasteride used for escitalopram 10 mg cialis pharmacy prices viagra without a doctor prescription lowest cialis prices levitra prices ciprofloxacin hcl 500 mg tab generic for cialis lexapro for anxiety ciprofloxacin hydrochloride ophthalmic cialis for daily use what does azithromycin treat azithromycin for strep throat viagra alternatives cialis medication finasteride cialis for men zithromax antibiotic lexapro dosage levitra 20mg cost per pill what is tamoxifen used for viagra effects tamoxifen cost ciprofloxacin side effects azithromycin 250mg azithromycin tablet azithromycin z pak acyclovir cipro and tendonitis lexapro bula levitra vs viagra lexapro benefits for women buy cialis cialis coupons from manufacturer viagra 100 mg what does viagra do acyclovir 400mg ciprofloxacin dosage acyclovir side effects viagra cialis viagra coupon pfizer viagra ciprofloxacin hydrochloride finasteride vs dutasteride side effects of azithromycin 250 mg what is cipro usually prescribed for tamoxifen therapy azithromycin eye drops equipe argentine viagra side effects of cialis post finasteride syndrome ciprofloxacin 500mg levitra 20mg azithromycin 250 viagra for women azithromycin coverage levitra online viagra dosage escitalopram 10mg lexapro 10mg zovirax pills cialis reviews azithromycin 250 mg treatment ciprofloxacin for dogs acyclovir medication cialis or viagra cialis 30 day sample buying viagra pfizer viagra coupons from pfizer finasteride 1mg acyclovir ointment free cialis ciprofloxacin used for cialis for bph cialis testimonials ciprofloxacin uses zoloft vs lexapro azithromycin 250mg tablets 6 pack azithromycin 5 day dose pack acyclovir 800 mg 5 times a day lexapro coupons viagra pillen kruidvat viagra single packs viagra ohne rezept auf rechnung acyclovir ointment 5 generic cialis at walmart buy cialis online price cialis what is azithromycin for cheap levitra viagra samples what is acyclovir for what infections does ciprofloxacin treat what is cipro used for viagra soft cheap viagra lexapro side effects in men thuoc azithromycin cialis vs viagra cipro 500 how does viagra work lexapro reviews finasteride 5 mg tab what bacteria does ciprofloxacin kill viagra azithromycine eg 500 mg bijsluiter what is azithromycin cialis for sale 9 levitra at walmart viagra vs cialis acyclovir for cold sores revatio vs viagra viamedic cialis how does lexapro work ciprofloxacin class zovirax dosage what is escitalopram viagra price acyclovir for shingles ciprofloxacin 250 mg cipro dosage viagra vs cialis vs levitra acyclovir vs valacyclovir finasteride side effects levitra bayer 20mg meilleur prix finasteride permanent side effects ciprofloxacin hcl 500 mg side effects cialis price tamoxifen lawsuits cialis for women tamoxifen interaction what is lexapro used for side effects of lexapro escitalopram side effects buy generic viagra vardenafil vs viagra acyclovir 200mg cialis prices tamoxifen and bone pain lexapro weight gain tamoxifen and weight gain viagra prices cialis pills what does ciprofloxacin 500mg treat free viagra effects of stopping lexapro suddenly what works better than viagra common side effects of ciprofloxacin 500 mg zithromax z-pak tamoxifen side effects side effects of ciprofloxacin 500 mg zithromax generic cialis tadalafil viagra tablet acyclovir 800 mg order viagra cialis otc how to use viagra what is cipro acyclovir 800 mg for shingles cialis side effects levitra 20 mg von bayer viagra sex cialis professional levitra 10 mg prezzo generic viagra 100mg azithromycin uses cipro uses viagra without a doctor prescription usa cialis 20 mg cialis sample acyclovir dosage for cold sores side effects of lexapro in women azithromycin medscape viagra uk finasteride side effects in men cipro dangers cialis on line acyclovir cream viagra vs cialis azithromycin tablets levitra coupon azithromycin cost levitra 20 mg precio farmacia ciprofloxacin ophthalmic solution escitalopram online viagra cialis canadian pharmacy viagra on line no prec zovirax for cold sores cialis vs viagra how much does cialis cost cialis 5 mg zithromax 500 mg cialis coupon propecia cialis dosage what is ciprofloxacin ciprofloxacin 500mg antibiotics side effects buy viagra online cialis patent expiration daily cialis viagra side effects cialis coupon print cialis coupons azithromycin pregnancy category side effects of finasteride 5mg viagra ohne rezept aus deutschland levitra 20 mg viagra costs buy levitra where to buy viagra tamoxifen side effects in women cipro side effects generic lexapro