To select only the letters from the given string ""five quacking zephyrs jolt my wax bed."", you can use the scan
method in Ruby along with a regular expression to match the letters.
Here's an example code snippet to achieve that:
main.rb105 chars5 lines
Output:
main.rb32 chars2 lines
In the code above, we use the scan
method with the regular expression [a-zA-Z]
to match all alphabetical letters (both lowercase and uppercase) in the string. We then use join
to combine all the matched letters into a single string.
Note that the backslash \
before each letter is removed in the selected letters because it is treated as an escape character.
gistlibby LogSnag