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

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 S. [email protected]
http://www.stok.co.uk/~mike/

The “`Stok’ disclaimers” apply.

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

Merry Christmas!

Back at ya. :wink:

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.

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 G. II

Thanks to James and Mike. Both suggestions work!

Happy holidays!
basi