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

  • Home
  • SEARCH
  • 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 628205
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T19:36:40+00:00 2026-05-13T19:36:40+00:00

or even better can I do hash.has_key?(‘videox’) where x is ” nothing or a

  • 0

or even better can I do hash.has_key?('videox') where x is

  • ” nothing or
  • a digit?

so ‘video’, ‘video1’, ‘video2’ would pass the condition?

of course I can have two conditions but in case I need to use video3 in the future things would get more complicated…

  • 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-05-13T19:36:41+00:00Added an answer on May 13, 2026 at 7:36 pm

    If you want the general case of video followed by a digit without explicitly listing all the combinations there are a couple of methods from Enumerable that you could use in combination with a regular expression.

    hash.keys is an array of the keys from hash and ^video\d$ matches video followed by a digit.

    # true if the block returns true for any element    
    hash.keys.any? { |k| k.match(/^video\d$/ }
    

    or

    # grep returns an array of the matching elements
    hash.keys.grep(/^video\d$/).size > 0
    

    grep would also allow you to capture the matching key(s) if you needed that information for the next bit of your code e.g.

    if (matched_keys = hash.keys.grep(/^video\d$/)).size > 0
      puts "Matching keys #{matched_keys.inspect}"
    

    Furthermore, if the prefix of key we’re looking for is in a variable rather than a hard coded string we can do something along the lines of:

    prefix = 'video'
    # use an interpolated string, note the need to escape the
    # \ in \d
    hash.keys.any? { |k| k.match("^#{prefix}\\d$") }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can you recommend any script/engine for image (with video would be even better) capturing
Even better would be if autoResize in latest branch would work as intended, but
Does anyone know of or even better.. can wholeheartedly recommend a WPF graph layout
Tool that can be used to migrate (or even better..synchronize) test cases and bugs
Is there any library (or even better, web service) available which can convert from
Even though I always strive for complete validation these days, I often wonder if
Even though I have a robust and fast computer (Pentium Dual Core 2.0 with
Even when BorderStyle is set to 0, it is possible to force a window
Even after all the hotfixes and updates that are supposed to fix this, my
Even a simple Notepad application in C# consumes megabytes of RAM as seen in

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.