Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8513771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T04:40:27+00:00 2026-06-11T04:40:27+00:00

Let say I have this string: a = Vallås centrum HALMSTAD And I would

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T04:40:29+00:00Added an answer on June 11, 2026 at 4:40 am

    Try this:

    a = "Vallås centrum ISN'T blah Blah HALMSTAD AND "
    b = a.gsub(/\b[A-Z]?[^A-Z\s']+\s*\b/, '')
    puts b
    

    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-Z with 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):

    \b(?:[^\s]?[[:lower:]][^\s]?)+\s*\b[?!]?
    

    Test the regex here

    Ruby Code:

    a = "Vallås centrum ISN'T blah Blah HALMSTAD AND BlaG and bLag's? FINISH "
    b = a.gsub(/\b(?:[^\s]?[[:lower:]][^\s]?)+\s*\b[?!]?/, '')
    puts b
    

    Fiddle with the code here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Using PHP, let's say I have this string: $letters = abcde; I would like
Let say I have a string like this sometext<br>sometext<br>sometext(Rating 50)<br>sometext<br> All I want to
Let's say I have a string like this: String test = hfikoebndolahsdHEL123LOkjahhsdqhuihs; And then
Let's say I have a string like this: var str = /abcd/efgh/ijkl/xxx-1/xxx-2; How do
Let's say I have a string like this. Dim str As String = code
Let's say I have a class like this (and also further assume that all
Let's say I have an array like this: string x[2][55]; If I want to
Let's say you have a string with embedded links and tags like so: This
Let's say I have this string var: string strData = 1|2|3|4||a|b|c|d Then, I make
Let's say I have this string: Hello &, how are you? I'm fine! Is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.