Re: Match First Sequence in Regular Expression?



"Jordan Abel" <random832@xxxxxxxxx> wrote in message
news:slrndthvsh.2npi.random832@xxxxxxxxxxxxxxxx
> On 2006-01-26, Roger L. Cauvin <roger@xxxxxxxxxxxx> wrote:
>> Say I have some string that begins with an arbitrary sequence of
>> characters
>> and then alternates repeating the letters 'a' and 'b' any number of
>> times,
>> e.g.
>>
>> "xyz123aaabbaabbbbababbbbaaabb"
>>
>> I'm looking for a regular expression that matches the first, and only the
>> first, sequence of the letter 'a', and only if the length of the sequence
>> is
>> exactly 3.
>>
>> Does such a regular expression exist? If so, any ideas as to what it
>> could
>> be?
>
> I believe posix regex libraries always yield only the first match.
>
> by "exactly 3" do you mean "Four shalt thou not count, neither count
> thou two, excepting that thou then proceed to three. Five is right
> out.", or do you mean the first occurence of 3 a's no matter what
> follows it?

Someone on another newsgroup provided a solution:

..*?(?<![ab])aaab

--
Roger L. Cauvin
nospam_roger@xxxxxxxxxx (omit the "nospam_" part)
Cauvin, Inc.
Product Management / Market Research
http://www.cauvin-inc.com


.



Relevant Pages

  • Re: Grammar States and Tertiary Phonemes
    ... can be 'described' by a sequence of ... decimal base numbering system has 10 letters in its 'alphabet': ... Then, we derive a *grammar*, which is effectively a set of both ...
    (soc.religion.islam)
  • Re: Match First Sequence in Regular Expression?
    ... > Roger L. Cauvin wrote: ... >> characters and then alternates repeating the letters 'a' and 'b' any ... >> first, sequence of the letter 'a', and only if the length of the sequence ...
    (comp.lang.awk)
  • Re: Match First Sequence in Regular Expression?
    ... but the second test case I listed contained a typo. ... >>contained a sequence of three of the letter 'a'. ... The requirements are not met by your regular expression, ... Cauvin, Inc. ...
    (comp.lang.python)
  • Re: Lennys Counter Argument
    ... "Not beyond very low levels of functional complexity this is by no ... "It is very much like adding letters to growing English-language ... sequence, like I or It, and then add another letter and have it be ... can fairly quickly produce a sequence of over a dozen characters. ...
    (talk.origins)
  • Re: Match First Sequence in Regular Expression?
    ... Roger L. Cauvin wrote: ... >>> I'm looking for a regular expression that matches the first, ... >>> first, sequence of the letter 'a', and only if the length of the sequence ...
    (comp.unix.questions)