开发者

How to change this Ruby regex to also include underlines?

开发者 https://www.devze.com 2023-01-19 12:58 出处:网络
At the moment I am using this line to take a string and extract only the letters from it: string.scan(/[a-zA-Z]/).to_s

At the moment I am using this line to take a string and extract only the letters from it:

string.scan(/[a-zA-Z]/).to_s

How do I modify this so that the underline character, "开发者_StackOverflow社区_", is also included? Thanks for reading.


Add it within the brackets (the range IIRC).

string.scan(/[a-zA-Z_]/).to_s


Alternative version

string.scan(/[a-z_]/i).to_s
0

精彩评论

暂无评论...
验证码 换一张
取 消