Results 1 to 5 of 5
  1. #1
    Join Date
    Aug 2003
    Location
    san jose, CA
    Posts
    68

    Unanswered: regular expression question?

    Hello everyone:

    I am doing a exercise which requires me to find out all the words that have six or more characters and doesn’t contains any of the five vowels(a, e, I, o, u)

    My code matched three words that satisfied the criteria
    While(<>) #process the text file
    {
    if(/……/ and !/a/i and !/e/i and !/i/i and !/o/i and !/u/i)
    {
    print “$_ \n”;
    }
    }
    I am wondering is this regular expression correct(will it match all the words satisfy the criteria)? Please help to confirm.

  2. #2
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    When you say six or more characters do you mean letters?

    Your regex will match seven spaces.

    perhaps you want something like

    m/^[b-df-hj-np-tv-z]{6,}$/i

  3. #3
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Quote Originally Posted by senza_nome
    When you say six or more characters do you mean letters?

    Your regex will match seven spaces.

    perhaps you want something like

    m/^[b-df-hj-np-tv-z]{6,}$/i
    As long as you assume one word per line, couldn't you also use:
    Code:
    m/^[^aeiou]{6,}$/i
    -PatP

  4. #4
    Join Date
    Jun 2004
    Location
    Nowhere Near You
    Posts
    89
    Pat,

    You're allowing any string of 6 or more characters (not necessarily letters) without any a,e,i,o,u! I suspect that a "word" in defined (in his dataset) as a string of alphabets.

  5. #5
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    Good point... It would sure help if people would actually post their assignments when they want us to do their homework, instead of just paraphrasing it! Of course, it would also help if I truly knew Perl instead of just beining an itinerant toy monger that enjoys playing with it.

    -PatP

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •