No, it didn't. I was trying to expand my horizons.
TobiMc3@gmail.com - 06 Aug 2007 16:34 GMT
On Aug 6, 11:21 am, "Tobi...@gmail.com" <Tobi...@gmail.com> wrote:
> No, it didn't. I was trying to expand my horizons.
If nothing else, I thought I could break it up. First test that it
contained two letters, then test that it contained two numbers.
Patricia Shanahan - 06 Aug 2007 16:55 GMT
> On Aug 6, 11:21 am, "Tobi...@gmail.com" <Tobi...@gmail.com> wrote:
>> No, it didn't. I was trying to expand my horizons.
>
> If nothing else, I thought I could break it up. First test that it
> contained two letters, then test that it contained two numbers.
I would probably use a single scan approach, with two counters, one for
letters and one for numbers.
Patricia
bugbear - 06 Aug 2007 17:37 GMT
>> On Aug 6, 11:21 am, "Tobi...@gmail.com" <Tobi...@gmail.com> wrote:
>>> No, it didn't. I was trying to expand my horizons.
[quoted text clipped - 4 lines]
> I would probably use a single scan approach, with two counters, one for
> letters and one for numbers.
If you want to be regex obsessed, you could...
if(/\d.*\d/ && /[a-zA-Z].*[a-zA-Z]/ && /^....$/)
(apols for typos etc)
BugBear
(original message didn't arrive here, which is why I'm replying to
Patricia's post.)
>> This is was part of a homework problem (I know how everyone loves
>> those :-) ) but now the homework is turned in, and I am left with a
[quoted text clipped - 7 lines]
>> from O'Reilly-but haven't had an opportunity to begin reading it in
>> earnest.
I don't think this is what you're looking for, but for what it's
worth, the way I learned Regular Expressions was from reading Michael
Sipser's Theory of Computation book
(http://www.amazon.com/Introduction-Theory-Computation-Michael-Sipser/dp/053494728X)
Note that he teaches "pure" regular expression, which doesn't contain
a lot of the fancy features which Perl or Java's regular expression have
(such as back-references).
Additionally, the book isn't intended to teach regular expressions in
particular, but rather covers it as part of the journey to learning theory
of computation in general (e.g. what is or is not possible to compute on a
computer, etc.)
>> The problem in question:
>>
[quoted text clipped - 5 lines]
>> was X1T5-a pattern where the digits or numbers were not right next to
>> each other.
The method I use is to draw whatever it is I want to verify as a
finite state machine (representing your condition as a state machine was
pretty straight forward, requiring only 5 states: [0 alpha 0 num], [1
alpha 0 num], [0 alpha 1 num], [1 alpha 1 num], [accepted]), and then
doing a simple, mechanical process to convert from the state diagram into
a regular expression (which is explained in the book).
The solution I have is quite long and messy, but it works. I'm not
sure if you want me to just post the solution I have, but otherwise I'm
not sure what kind of "hints" I could give, other than the implicit hint
above being the names of my 5 states.
- Oliver
fireflyc - 07 Aug 2007 01:29 GMT
> (original message didn't arrive here, which is why I'm replying to
> Patricia's post.)
[quoted text clipped - 49 lines]
>
> - Oliver
i think you need a small book.
a tao of regular.
you can google it.