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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:05:23+00:00 2026-06-03T03:05:23+00:00

I am trying to create a program where two strings are entered. If they

  • 0

I am trying to create a program where two strings are entered. If they match it returns the number of positions where they contain the same length 2 substring.

for example:string_match(‘xxcaazz’, ‘xxbaaz’) → 3 “xx” “aa” “az”
My question is what metacharacters should i use to validate

here is what i have come up with

puts "enter word"
a = STDIN.gets
a.chomp!
puts"enter word"
b = STDIN.gets
b.chomp!
if a == /word/ or b == /word/ then 
  puts str.match(/{a} {b}/) + "equal"
end
  • 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-03T03:05:24+00:00Added an answer on June 3, 2026 at 3:05 am

    UPDATED ANSWER:

    ( Still spiked, but better )

    first_word = 'xxcaazz'.split('')
    second_word ='xxbaaz'.split('')
    
    first_word_length = first_word.length
    second_word_length = second_word.length
    
    if [first_word_length, second_word_length].min == first_word_length
      inner_word = second_word
      outter_word = first_word
    else
      inner_word = first_word
      outter_word = second_word
    end
    
    outter_word_length = outter_word.length - 2
    
    word_matches = 0
    
    (0..outter_word_length).each do |character|
      if "#{outter_word[character]}#{outter_word[character + 1]}" == "#{inner_word[character]}#{inner_word[character + 1]}"
        puts "#{outter_word[character]}#{outter_word[character + 1]}"
        word_matches += 1
      end
    end
    
    puts "Found #{word_matches} matches"
    

    ORIGINAL SPIKE:

    This may get you off to a good start ( though it’s by no means bullet proof, just a quick spike ):

    first_word = 'xxcaazz'.split('')
    second_word ='xxbaaz'.split('')
    first_word_length = first_word.length
    
    (0..first_word_length).each do |character|
      if "#{second_word[character]}#{second_word[character + 1]}" == "#{first_word[character]}#{first_word[character + 1]}"
        puts "#{second_word[character]}#{second_word[character + 1]}"
      end
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create a program which takes in a set number of strings
I'm trying to create a program that will return a certain number decomposed to
I'm trying to create a program that takes a text file of c++ code
I am trying to create a program similar to Folder Lock which prevents users
I am trying to create a program that will do some simple calculations, but
I am trying to create a program that has one tableview and when you
I'm currently trying to create a program that estimates location based on signal strength.
I'm trying to create a python program (using pyUNO ) to make some changes
I have been trying to create a simple program with Python which uses OpenCV
I am trying to create a small assembly program to create a folder. I

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.