|
-
March 17th, 2010, 12:53 PM
#1
Regex - finding words with two e's
Hello again, another question from me!
Alright I am working on an assignment. And I haven't been able to figure out what the regex syntax would be to search for words, within a string, with atleast 2 e's. This is what I have right now.
but this only finds words like 'here'. I need it to return the word no matter where the e's are in the word, as long as there are atleast 2 in the word.
Thanks in advance for any help.
-
March 17th, 2010, 01:45 PM
#2
Re: Regex - finding words with two e's
there's probably more efficient ways of doing this but here is the logic I would use..
I did not test this, but it should work;
Code:
function getWordsWithDblEs($myWord){
$myLetterArray = str_split($myWord);
$i=0;
foreach($myLetterArray as $checkletters){
if($checkletters == "e"){
$i++;
}
}
if($i >= 2){
echo "the letter \"e\" is found ".$i." times in the word ".$myWord;
}else{
echo "this word have less than two e";
}
}
you might want to handle cap sensitivity... and have line 5 say
Code:
if(strtoupper($checkletters) == strtoupper("e")){
note that my function is simply echoing stuff... you might want to "return" a value if true or false...
Last edited by bobo; March 17th, 2010 at 02:34 PM.
-
March 17th, 2010, 03:47 PM
#3
Re: Regex - finding words with two e's
My teacher wants us to use regular expressions.
What the script does is read a file and store the lines in an array. I am finding only the word that are e{any letter}e (here, there, were, etc...) and then it out puts the number of words in each string that have at least 2 e's. I am not counting the number of e's in each word.
-
March 17th, 2010, 04:12 PM
#4
Re: Regex - finding words with two e's
Code:
/\w*ee\w*|\w*e[^>]*e\w*/i
Two conditions separated by a |
- Any word containing "ee" back to back.
- Two "e" characters separated by any other character...all within the word boundary.
Last edited by PeejAvery; March 17th, 2010 at 04:15 PM.
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|