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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T12:15:07+00:00 2026-06-07T12:15:07+00:00

I am new to ruby and regular expressions and trying to figure out how

  • 0

I am new to ruby and regular expressions and trying to figure out how to attack seperating the attached string of baseball players into first/last name combinations.

This is a sample string:

"JohnnyCuetoJ.J.PutzBrianMcCann"

This is the desired output:

Johnny Cueto
J.J. Putz
Brian McCann

I have figured out how to separate by capital letters which gets me close, but the outlier names like J.J. and McCann mess that pattern up. Anyone have ideas on the best way to approach 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-07T12:15:08+00:00Added an answer on June 7, 2026 at 12:15 pm

    If you don’t have to do it in one single gsub than it gets a bit easier.

    string = "JohnnyCuetoJ.J.PutzBrianMcCann"
    string.gsub!(/([A-Z][^A-Z]+)/, '\1 ') # separate by capital letters
    string.gsub!(/(\.) ([A-Z]\.)/, '\1\2') # paste together "J. J." -> "J.J."
    string.gsub!(/Mc /, 'Mc') # Remove the space in "Mc "
    string.strip # Remove the extra space after "Cann "
    

    …and of course you can put this on a single line by chaining the gsub calls, but that will basically kill the readability of the code (but on the other hand, how readable is a block of regexen anyway?)

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

Sidebar

Related Questions

Hi I'm new to Ruby and regular expressions. I'm trying to use a regular
I am trying to use regular expressions in a ruby on rails app to
I'm brand new to ruby and rails and I'm having trouble creating a sign-out
I have some regular expressions in my database which are then instantiated in Ruby
I'm a new ruby/rails user trying to get my mac set up for the
I am kinda new to Ruby and still trying to understand some of the
I'm very new to Redmine/Ruby trying to achieve a simple plugin that takes the
I am trying to get familiar with the new ruby selenium-webdriver as it appears
I am new at Ruby on Rails. I was trying to validate format of
I'm brand new to ruby on rails and trying to run an application developed

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.