# Scanning for more than one specific character with String#sc

**URL:** <https://www.ruby-forum.com/t/scanning-for-more-than-one-specific-character-with-string-sc/53220>\
**Category:** Ruby\
**Created:** [January 29, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/scanning-for-more-than-one-specific-character-with-string-sc/53220 "2006-01-29T18:34:09Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![braas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f04885/32.png) [@braas](https://www.ruby-forum.com/u/braas)\
**Post date:** [January 29, 2006, 6:34pm UTC](https://www.ruby-forum.com/t/scanning-for-more-than-one-specific-character-with-string-sc/53220/1 "2006-01-29T18:34:09Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![braas](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/f04885/32.png) [@braas](https://www.ruby-forum.com/u/braas)\
**Post date:** [January 29, 2006, 6:49pm UTC](https://www.ruby-forum.com/t/scanning-for-more-than-one-specific-character-with-string-sc/53220/2 "2006-01-29T18:49:14Z")

</div>

Greetings,

On 1/29/06, Jeppe J. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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
