Page 1 of 1
Simple question!
Posted: Tue Jan 06, 2009 6:12 pm
by Brodster
How can I make sure the whole word is matched?
For example say I want to test for ONLY letters [abcdef]?
If i use /[abcdef]/ both "aaaaaaabbbb" and "aaaaaaakkkkk" will match. I want to make sure EVERY letter matches the pattern I give.
Can this be done?
P.S. I do not know the length of the word ahead of time so I can not use [abcdef]{x} where x is the length of the word
Re: Simple question!
Posted: Wed Jan 07, 2009 3:45 am
by prometheuzz
Brodster wrote:How can I make sure the whole word is matched?
For example say I want to test for ONLY letters [abcdef]?
If i use /[abcdef]/ both "aaaaaaabbbb" and "aaaaaaakkkkk" will match. I want to make sure EVERY letter matches the pattern I give.
Can this be done?
P.S. I do not know the length of the word ahead of time so I can not use [abcdef]{x} where x is the length of the word
The regex '/[abcdef]/' will match a single letter anywhere in the regex, that's why "aaaaaaakkkkk" matches.
You will have to do '/[abcdef]+/', where the + means one or more. But if you try that, still "aaaaaaakkkkk" matches: the "aaaaaaa" now is the match.
So, you will have to "anchor" the beginning (^) and ending ($) of the string with that last pattern to make sure all characters in the string match it:
Re: Simple question!
Posted: Thu Jan 15, 2009 11:07 am
by piyushj
write a regular expression for the only strings that are not generated over {a,b} by the expression (a+ b)* a (a+b)*
reasoning please
Re: Simple question!
Posted: Thu Jan 15, 2009 11:20 am
by piyushj
Write a regular expression for strings that contain atleast one a and one b. show that its capable of generating the strings :
(i) aabbbabaa
(ii) bbbbaaa
Re: Simple question!
Posted: Fri Jan 16, 2009 5:23 am
by prometheuzz
piyushj wrote:Write a regular expression for strings that contain atleast one a and one b. show that its capable of generating the strings :
(i) aabbbabaa
(ii) bbbbaaa
As I suggested two times now: create your own thread instead of hijacking other people's thread.