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 8645457
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:33:24+00:00 2026-06-12T12:33:24+00:00

With the expression below: words = string.scan(/\b\S+\b/i) I am trying to scan through the

  • 0

With the expression below:

words = string.scan(/\b\S+\b/i)

I am trying to scan through the string with word boundaries and case insensitivity, so if I have:

string = "A ball a Ball" 

then when I have this each block:

words.each { |word| result[word] += 1 }

I am anticipating something like:

{"a"=>2, "ball"=>2}

But instead what I get is:

{"A"=>1, "ball"=>1, "a"=>1, "Ball"=>1}

After this thing didnt work I tried to create a new Regexp like:

Regexp.new(Regexp.escape(string), "i")

but then I do not know how to use this or move forward from here.

  • 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-12T12:33:25+00:00Added an answer on June 12, 2026 at 12:33 pm

    The regex matches words in case-insensitive mode, but it doesn’t alter matched text in any way. So you will receive text in its original form in the block. Try casting strings to lower case when counting.

    string = "A ball a Ball" 
    words = string.scan(/\b\S+\b/i) # => ["A", "ball", "a", "Ball"]
    
    result = Hash.new(0)
    words.each { |word| result[word.downcase] += 1 } 
    result # => {"a"=>2, "ball"=>2}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string as below: 4s: and in this <em>new</em>, 5s: <em>year</em> everybody
I have this method: public static Expression<Func<MyEntity, bool>> MyMethod(string someId) { return o =>
I have a regular expression below that works for a string example like: MCCOY
I am trying to fill my datatable using LINQ expression below , this works
Just out of curiosity, asking this Like the expression one below a = (condition)
I have the below xpath expression //div[@class=post-content]//img which runs on a html page, scanning
I'm trying to add the character Ö (U+00D6) to my regular expression below. Apparently
What do I have to change in this regular expression so that in both
I have string like below case1: str = type=\text/xsl\ href=\http://skdjf.sdjhshf/CDA0000=.xsl\ case2: str = href=\http://skdjf.sdjhshf/CDA0000=.xsl\
For example I have code below string txt=I have strings like West, and West;

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.