Dinara, Steven,<br><br><div class="gmail_quote">On 4 November 2011 23:29, Steven D&#39;Aprano <span dir="ltr">&lt;<a href="mailto:steve@pearwood.info">steve@pearwood.info</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

Is this homework? You should have said so.<br></blockquote><div><br>Inded he should&#39;ve...<br> </div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">


I don&#39;t understand questions like this. Do carpenters ask their apprentices to cut a piece of wood with a hammer? Do apprentice chefs get told to dice carrots using only a spoon? Computer programming is the only skill I know of where teachers routinely insist that students use inappropriate tools to solve a problem, just to prove they can do it.<br>
</blockquote><div><br>Calm down dear, it&#39;s only a reg-ex... ;) <br><br>Additionally, if I may say so, I find this part of your response rather less than helpful, it&#39;s rant-ish IMHO, and as far as I&#39;m concerned the apprentice analogies are not akin to what programming teachers do and why they do it.  Fact is, people need to learn the tools of their trade somewhere.  Sometimes it&#39;s neccesary to focus on a particular tool and therefore dream up some artificial problem for the sake of learning to use the tool.  It&#39;s not that apprentices are being taught to cut wood with a hammer or whatnot.  And yes, regular expression can be damn useful sometimes.  Whether or not you like regular expressions, use them, or are good at them have no bearing on whether Dinara should be able learn how to use them, nor is it relevant what you think of the question or if the context of the learning is a contrived question/excercise.   <br>
<br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<br>
In any case, if this is even possible using regular expressions -- and I don&#39;t think it is -- I have no idea how to do it. Good luck. Maybe somebody else might have a clue.<br></blockquote><div><br>@Dinara:<br><br>It is actually.  Let&#39;s describe the requirement a bit differently, first in words, then see if we can write a regular expression that will match that description:  A word that matches our requirement will start with 0 or more occurences of a, and be followed by 0 or more occurrences of b, and so on, until z, after which we must have reached the end of the word.  So the requirements for the regex is:<br>
1.) The regex must start at the beginning of the string<br>2.) 0 or more a&#39;s may be matched, followed by 0 or more b&#39;s, followed by 0 or more c&#39;s and son on, up to z,<br>3.) The regex must end at the end of the string (so 1 and 3 together imply 
that all the text in the string must be matched/consumed by the regex 
for a match to have been found.<br><br>If we write an equivalent regex, to the above requirement, and it matches all the text in a string (e.g. a match is found), then by definition it will have found a word containing letters in alphabetized order.  The only special case to handle would be the empty string -- this would be matched by the above regex but may not be considered correct per the intent of the problem. (On the other hand, an empty string is not a word either, so one might consider this invalid input in the first place and should properly probably reject the input and refuse to process it.)<br>
<br>I&#39;ll give you some further hints.  <br><br>1.) To specify/match the beginning of a string, you use the ^ character in a regex.<br>2.) To specify 0 or more of something you append an asterisk, e.g. *<br>3.) To specify a letter to be matched, you can write it directly.  To therefore match 0 or more a&#39;s for example, you&#39;d write a*<br>
4.) To specify a sequence of things you simply write them out.  So for example the regular expression a*b* will match strings like &#39;ab&#39;, &#39;aab&#39;, &#39;abb&#39;, &#39;b&#39;, &#39;a&#39;, but not &#39;baa&#39;...<br>
5.) To specify the end of a string, you use the $ character in a regex.<br><br>By the way, it&#39;s possible to write an alternatve version of the function that Steven provied in a single line (of body code) with a regex.  <br>
<br>HTH,<br><br>Walter<br></div></div><br>