[Newbies] Re: Regular Expression Question
me at zulq.net
Sun Jan 27 06:47:53 UTC 2008
> 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')"
More information about the Beginners