[Top][All Lists]

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

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

From: Rick Flower
Subject: [Help-smalltalk] GST's regex syntax..
Date: Tue, 23 Oct 2012 12:48:38 -0700
User-agent: Apple Webmail/0.6

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!

reply via email to

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