[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] GST's regex syntax..

From: Leszek Kowalczyk
Subject: Re: [Help-smalltalk] GST's regex syntax..
Date: Tue, 23 Oct 2012 23:05:26 +0200


> Date: Tue, 23 Oct 2012 12:48:38 -0700
> From: address@hidden
> To: address@hidden
> Subject: [Help-smalltalk] GST's regex syntax..
> Ok.. So I'm chewing text again.. this time with regular expressions..
> I'm having problems with repeating patterns that I'm hoping to solve..
> If I've got the string "My DOG and CAT ate the BIG blue BIRD" in the
> file "foo.txt" and want to find all uppercase 3 & 4 letter words I was
> hoping to use the following code snippet :
> | fileStream coll |
> fileStream := FileStream open: 'foo.txt' mode: FileStream read.
> coll := OrderedCollection new.
> fileStream linesDo: [:line |
>       (line =~ '([A-Z]{3,4})+') ifMatched: [:match | coll add: match].
> ].
> coll inspect.
> However the result is just DOG -- the others are missing.. What is 
> wrong
> with the repeating aspect of it where there are multiple hits within a
> single line?  It works fine for one hit per line but not multiples..
> Any ideas?  Thanks!

>From manual:

1.155.9 String: regex

=~ patternAnswer a RegexResults object for matching the receiver against
the Regex or String object pattern.

allOccurrencesOfRegex: patternFind all the matches of pattern within the 
receiver and
collect them into an OrderedCollection.

allOccurrencesOfRegex: pattern do: aBlockFind all the matches of pattern within 
the receiver and
pass the RegexResults objects to aBlock.

So =~ looks for first occurrence, try other one, and the match then is an 

Best regards,

reply via email to

[Prev in Thread] Current Thread [Next in Thread]