Forum: Ruby Regex: how to match duplicate syllables?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Acdabad15b58ba105df230e3ea02523d?d=identicon&s=25 basi (Guest)
on 2005-12-25 04:28
(Received via mailing list)
Merry Christmas!

But work goes on :(

Just trying a way to match duplicate syllables.

C = "bcdfghjklmnpqrstvwxyz"
V = "aeiou"

aString =~ /[#{C}][#{V}][#{C}][#{V}]/

should match if the first CV matches the next CV. Hence, "waikiki"
should match on "kiki". And  "dodo", "paparazzi" should match too.

Thanks!
basi
4299e35bacef054df40583da2d51edea?d=identicon&s=25 James Gray (bbazzarrakk)
on 2005-12-25 05:01
(Received via mailing list)
On Dec 24, 2005, at 9:27 PM, basi wrote:

> Merry Christmas!

Back at ya.  ;)

> But work goes on :(

<laughs>

> Just trying a way to match duplicate syllables.
>
> C = "bcdfghjklmnpqrstvwxyz"
> V = "aeiou"
>
> aString =~ /[#{C}][#{V}][#{C}][#{V}]/
>
> should match if the first CV matches the next CV. Hence, "waikiki"
> should match on "kiki". And  "dodo", "paparazzi" should match too.

Hope this helps:

 >> V = "aeiou".freeze
=> "aeiou"
 >> C = ("a".."z").to_a.join.gsub(/[#{V}]/, "").freeze
=> "bcdfghjklmnpqrstvwxyz"
 >> DBL_SYL = /([#{C}][#{V}])\1/.freeze
=> /([bcdfghjklmnpqrstvwxyz][aeiou])\1/
 >> %w{waikiki dodo paparazzi}.each do |test|
?>   puts "#{test} => #{$&}" if test =~ DBL_SYL
 >> end
waikiki => kiki
dodo => dodo
paparazzi => papa
=> ["waikiki", "dodo", "paparazzi"]

James Edward Gray II
Cb7d2cb319c70e49fa1522614980e128?d=identicon&s=25 Mike Stok (Guest)
on 2005-12-25 05:07
(Received via mailing list)
On 24-Dec-05, at 10:27 PM, basi wrote:

>
> should match if the first CV matches the next CV. Hence, "waikiki"
> should match on "kiki". And  "dodo", "paparazzi" should match too.

What about using \1 e.g.

C = "bcdfghjklmnpqrstvwxyz"
V = "aeiou"

%w{ kiki dodo paparazzi abacab }.each do |word|
   puts "#{word} matched" if word =~ /([#{C}][#{V}])\1/
end

Hope this helps,

Mike

--

Mike Stok <mike@stok.co.uk>
http://www.stok.co.uk/~mike/

The "`Stok' disclaimers" apply.
Acdabad15b58ba105df230e3ea02523d?d=identicon&s=25 basi (Guest)
on 2005-12-25 05:34
(Received via mailing list)
Thanks to James and Mike. Both suggestions work!

Happy holidays!
basi
This topic is locked and can not be replied to.