# Regex: how to match duplicate syllables?

**URL:** <https://www.ruby-forum.com/t/regex-how-to-match-duplicate-syllables/51059>\
**Category:** Ruby\
**Created:** [December 25, 2005, 4:28am UTC](https://www.ruby-forum.com/t/regex-how-to-match-duplicate-syllables/51059 "2005-12-25T04:28:49Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![basi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a3d4f5/32.png) [@basi](https://www.ruby-forum.com/u/basi)\
**Post date:** [December 25, 2005, 4:28am UTC](https://www.ruby-forum.com/t/regex-how-to-match-duplicate-syllables/51059/1 "2005-12-25T04:28:49Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![basi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a3d4f5/32.png) [@basi](https://www.ruby-forum.com/u/basi)\
**Post date:** [December 25, 2005, 5:07am UTC](https://www.ruby-forum.com/t/regex-how-to-match-duplicate-syllables/51059/2 "2005-12-25T05:07:53Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
[http://www.stok.co.uk/~mike/](http://www.stok.co.uk/~mike/)

The “`Stok’ disclaimers” apply.

---

<div class="post-metadata">

**Author:** ![basi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a3d4f5/32.png) [@basi](https://www.ruby-forum.com/u/basi)\
**Post date:** [December 25, 2005, 5:01am UTC](https://www.ruby-forum.com/t/regex-how-to-match-duplicate-syllables/51059/3 "2005-12-25T05:01:51Z")

</div>

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

> Merry Christmas!

Back at ya. 😉

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

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

---

<div class="post-metadata">

**Author:** ![basi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/a3d4f5/32.png) [@basi](https://www.ruby-forum.com/u/basi)\
**Post date:** [December 25, 2005, 5:34am UTC](https://www.ruby-forum.com/t/regex-how-to-match-duplicate-syllables/51059/4 "2005-12-25T05:34:54Z")

</div>

Thanks to James and Mike. Both suggestions work!

Happy holidays!  
basi
