Regex: how to match duplicate syllables?

Merry Christmas!

But work goes on :frowning:

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

Merry Christmas!

Back at ya. :wink:

But work goes on :frowning:

<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

路路路

On Dec 24, 2005, at 9:27 PM, basi wrote:

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

路路路

On 24-Dec-05, at 10:27 PM, basi wrote:

Merry Christmas!

But work goes on :frowning:

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.

--

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

The "`Stok' disclaimers" apply.

Thanks to James and Mike. Both suggestions work!

Happy holidays!
basi