logo       

Re: Regular Expression Question: msg#00133

lang.smalltalk.squeak.beginners

Subject: Re: Regular Expression Question

pbohuch wrote:


testString := 'this is a test'.
testCollection := '(^\s*)|(\s)|\w+' asRegex matchesIn: testString.


If I execute this in a workspace, I get an infinite loop. I think it's a problem with the expression - don't ^\s* and \w+ look for the same thing? Anyway, wouldn't '\w+|\s+' do what you want?

'this is a test' allRegexMatches: '\w+|\s+'
"=> ('this' ' ' 'is' ' ' 'a' ' ' 'test')"

Or if you just want the words, '\w+'. And, if you just want the words then you can probably just use #findTokens:

'this is a test' findTokens: ' '
"=> ('this' 'is' 'a' 'test')"

Regards,
Zulq.


<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise