Let say I have this string: a = "Vallås centrum HALMSTAD"
And I would like to remove all lowercase, whitespace and the first uppercase letter so I only have a string with a => "HALMSTAD"
I tried something like this:
a = "Vallås centrum HALMSTAD"
b = a.gsub(/[:lower:]/, "")
puts b
But I get this output: a => "Vaås cntum HALMSTAD"
any ideas on how to to do this?
Try this:
This should take care of most lower case words but you need to deal with other possible cases where you have punctuation symbols, question marks, exclamation marks, non-ASCII characters, etc…
You can fiddle with this here
In view of @TimPietzcker’s comment of non-ASCII characters, you could replace the
A-Zwith the POSIX bracket expression[[:upper:]]UPDATE:
This would be a more complete solution:
Regex to find most lowercase words (This can still be extended for more symbols):
Test the regex here
Ruby Code:
Fiddle with the code here