Reputation: 29
I want to replace capitals with spaces. An example string is "Hey MrsMccarthy"
. I want it to return " ey rs ccarthy"
.
I tried different ways shown here to adapt it to my problem, but it doesn't seem to work. I first looked at how to find the capitals, for which I used:
string.scan /\p{Upper}/ # => ["H", "M", "M"]
but I am not sure how to combine so that it returns:
"ey rs ccarthy"
Upvotes: 1
Views: 604
Reputation: 107037
I would do it like this:
string = "Hey MrsMccarthy"
string.gsub(/\p{Upper}/, ' ')
#=> " ey rs ccarthy"
Upvotes: 3