braas
1
Hi all, here is my question:
Lets say that I have a variable:
aString = “1234s * 4234k”
I’ll then like to scan for the units (the s and the k) after each
integer:
anArray = aString.scan(/s/)
Well that got me the s, but what expression do I have to use, if I want
to
scan for both s and k?
braas
2
Greetings,
On 1/29/06, Jeppe J. [email protected] wrote:
Lets say that I have a variable:
aString = “1234s * 4234k”
I’ll then like to scan for the units (the s and the k) after each integer:
anArray = aString.scan(/s/)
Well that got me the s, but what expression do I have to use, if I want to
scan for both s and k?
if you have an explicit list:
anArray = aString.scan(/[sk]/) #=> [“s”, “k”]
if you just want any lowercase letter:
anArray = aString.scan(/[a-z]/) #=> [“s”, “k”]
String.scan takes a regex, you might want to look into that. Have fun!
Cameron