PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Autres forums > Forum Programmation & Conception > comp.lang.ruby > how to do this regex substitution?
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
how to do this regex substitution?

Réponse
 
LinkBack Outils de la discussion
Vieux 09/05/2008, 03h41   #1
globalrev
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut how to do this regex substitution?

i want to replaxe the pattrn consonant o consonant, ie hoh -> h, dad -
> d etc.


so i have to check that the letter after the letter i am at is o and
the next one is equal to the one i am at.

so
/qwrtpsdfghjklzxcvbnm/o/qwrtpsdfghjklzxcvbnm isnt true(and doesnt work
anyway).

  Réponse avec citation
Vieux 09/05/2008, 04h29   #2
Peña, Botp
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to do this regex substitution?

From: globalrev [mailto:skanemupp@yahoo.se]=20
# i want to replaxe the pattrn consonant o consonant, ie hoh -> h, dad -
# > d etc.
# so i have to check that the letter after the letter i am at is o and
# the next one is equal to the one i am at.

hi globalrev,

there are many ways.

best if you can play in irb,

"hoh" =3D~ /(.)o\1/
#=3D> 0

"testhoh" =3D~ /(.)o\1/
#=3D> 4

$1
#=3D> "h"

if "testhoh".match(/(.)o\1/)
"match!"
else
"sorry"
end
#=3D> "match!"

"qwxoxtyasdfzozghj".gsub(/(.)o\1/) do |m|
p [m,$1,$~.pre_match,$~.post_match,$~.captures]
end
["xox", "x", "qw", "tyasdfzozghj", ["x"]]
["zoz", "z", "qwxoxtyasdf", "ghj", ["z"]]
#=3D> "qwtyasdfghj"

"qwxoxtyasdfzozghj".gsub(/(.)o\1/) do |m|
$1
end
#=3D> "qwxtyasdfzghj"

"qwxoxtyasdfzozghj".gsub(/(.)o\1/) do |m|
"<#$1>"
end
#=3D> "qw<x>tyasdf<z>ghj"

"qwxoxtyasdfzozghj".gsub(/(.)o\1/){"<#$1>"}
#=3D> "qw<x>tyasdf<z>ghj"

your next task now is to determine whether a certain char is a consonant =
regardless of case.

kind regards -botp

  Réponse avec citation
Vieux 10/05/2008, 18h51   #3
Peter Jones
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: how to do this regex substitution?

globalrev <skanemupp@yahoo.se> writes:
> i want to replaxe the pattrn consonant o consonant, ie hoh -> h, dad -
>> d etc.

>
> so i have to check that the letter after the letter i am at is o and
> the next one is equal to the one i am at.
>
> so
> /qwrtpsdfghjklzxcvbnm/o/qwrtpsdfghjklzxcvbnm isnt true(and doesnt work
> anyway).


You question is a bit confusing. You said you wanted to replace:

consonant o consonant

with:

consonant

Yet, one of your examples is dad, which doesn't fit that pattern. Did
you mean "consonant vowel consonant"?

Either way, here is one possibility. I'll leave "dad" as an exercise.

,----
| >> "hoh".sub(/([qwrtpsdfghjklzxcvbnm])o\1/, '\1')
| => "h"
`----

--
Peter Jones [pjones at domain below]
pmade inc. - http://pmade.com
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 17h29.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,11287 seconds with 11 queries