You are not logged in.

#1 2012-05-03 17:25:35

CSNate
Member
Registered: 2012-04-10
Posts: 3

Finding Words with more than Two Vowels (Regex)

Hello all, I've been working on this for quite some time now.  I need to use a regular expression to find words that contain more than two vowels.  I am getting stuck.

Here is what I have so far.  I am using emacs to find them in a text file.

I use C-M-s and the expression /<[^aeiou]*[aeiou][^aeiou]/>

It finds words with one vowel, but I need to find if it has more than two, and I'm not sure how to go about doing that.

Any help is appreciated!

Offline

#2 2012-05-03 18:27:59

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Finding Words with more than Two Vowels (Regex)

I've never used emacs, but grep seems to work with

LANG=C egrep '^([^aieou]*[aieou]){3,}[^aieou]*$' <filename>

modified from http://matt.might.net/articles/sculpting-text/


Edit: '{3,}' means simply 'three or more' of the preceding element.

Last edited by karol (2012-05-03 18:31:43)

Offline

#3 2012-05-03 18:31:01

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Finding Words with more than Two Vowels (Regex)

This better not be a homework question...

[aeiou].*[aeiou].*[aeiou]

or, more succinctly (I think...)

\([aeiou].*\)\{3\}

I tested it with grep on a file with one word per line.  Seems to work in that context.  More than one word per line and it breaks.  I know nothing of emacs or your data, so I have no idea if it will suffice.

I'd also suggest you go back over your expression and put into words exactly what you think it is doing.  I'm no regex expert, but it doesn't seem at all fit for what you're trying to do.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#4 2012-05-03 18:34:18

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Finding Words with more than Two Vowels (Regex)

alphaniner wrote:

I tested it with grep on a file with one word per line.  Seems to work in that context.  More than one word per line and it breaks.

Works here:

$ egrep '^([^aieou]*[aieou]){3,}[^aieou]*$' t1
aaa uuui
aaa bbb
bbaa bbaaiuo

Offline

#5 2012-05-03 18:41:52

alphaniner
Member
From: Ancapistan
Registered: 2010-07-12
Posts: 2,810

Re: Finding Words with more than Two Vowels (Regex)

Yeah, but he wants words, not lines.  My suggestion also matches the line

adste e

for example.


But whether the Constitution really be one thing, or another, this much is certain - that it has either authorized such a government as we have had, or has been powerless to prevent it. In either case, it is unfit to exist.
-Lysander Spooner

Offline

#6 2012-05-03 19:16:47

CSNate
Member
Registered: 2012-04-10
Posts: 3

Re: Finding Words with more than Two Vowels (Regex)

alphaniner wrote:

This better not be a homework question...

[aeiou].*[aeiou].*[aeiou]

or, more succinctly (I think...)

\([aeiou].*\)\{3\}

I tested it with grep on a file with one word per line.  Seems to work in that context.  More than one word per line and it breaks.  I know nothing of emacs or your data, so I have no idea if it will suffice.

I'd also suggest you go back over your expression and put into words exactly what you think it is doing.  I'm no regex expert, but it doesn't seem at all fit for what you're trying to do.

Thanks that seemed to work!

Offline

#7 2012-05-04 00:26:03

fukawi2
Ex-Administratorino
From: .vic.au
Registered: 2007-09-28
Posts: 6,231
Website

Re: Finding Words with more than Two Vowels (Regex)

WFM:

grep -P '\b([a-z]*[aeiou][a-z]*){2,}\b' *

Offline

#8 2012-05-05 19:26:08

zorro
Member
Registered: 2011-11-18
Posts: 47

Re: Finding Words with more than Two Vowels (Regex)

sed -nr '/([aeiou][a-z]*){3}/p'

Last edited by zorro (2012-05-05 19:27:39)

Offline

#9 2012-05-06 19:33:45

rowdog
Member
From: East Texas
Registered: 2009-08-19
Posts: 118

Re: Finding Words with more than Two Vowels (Regex)

FWIW, y is also a vowel, just ask any psychotic ;^)

Offline

#10 2012-05-06 20:14:47

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: Finding Words with more than Two Vowels (Regex)

rowdog wrote:

FWIW, y is also a vowel, just ask any psychotic ;^)

What is a vowel differs from language to language.

Offline

Board footer

Powered by FluxBB