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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T15:33:55+00:00 2026-06-13T15:33:55+00:00

I have a string like: hn$8m3kj4.23hs@8; i need to split it as follow: first

  • 0

I have a string like:

hn$8m3kj4.23hs@8;

i need to split it as follow: first entry should be of one char length, second entry of 2 chars, third entry of one char, fourth – by 2 chars and so on.

then concatenate one char with two chars entries by a semicolon :

if some chars at the end remains unpaired, they should be displayed as well.

it is important to skip all non alphanumeric chars.

so the final string should be:

h:n8 m:3k j:42 3:hs 8:

see, 8 has no 2 chars pair but it is displayed anyway.

i have tried with a loop but i get huge code.
also tried regexs but it split by wrong number of chars.

  • 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-13T15:33:56+00:00Added an answer on June 13, 2026 at 3:33 pm

    you can try this:

     s = "hn$8m3kj4.23hs@8;"
    
     s.gsub(/\W/, '').scan(/(.)(..)?/).map { |i| i.join ':' }.join ' '
     => "h:n8 m:3k j:42 3:hs 8:"
    

    this will not skip underscores though.

    if you need to skip them as well, use this one:

    s = "hn$8m3k_j4.23hs@8;_"
    
    s.gsub(/\W|_/, '').scan(/(.)(..)?/).map { |i| i.join ':' }.join ' '
    => "h:n8 m:3k j:42 3:hs 8:"
    

    See live demo here

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

Sidebar

Related Questions

I have string like this first#second, and I wonder how to get second part
I have string like this 0 0.014E5 and I need it split into a
I have string like {param1=foo}{param2=bar}hello world! I need to extract array of tuples (paramName,
I have string looking like this: 'Toy Story..(II) (1995)' I want to split the
I have String like this: LODIXAL COMP 15 How can i split it to
I have string like this: command . / * or any other char like
I have string like that: string val = 555*324-000 now, I need to remove
I have string like fullData1 upto fullData10 in this i need to separate out
I have a string like How\Are\You-1 . I need to substring till to You-1
Lets say I have string like this: String q = foo (one) bla (two)

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.