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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:22:02+00:00 2026-05-26T00:22:02+00:00

i am trying to get an array that contain of aaaaa,bbbbb,ccccc as split output

  • 0

i am trying to get an array that contain of aaaaa,bbbbb,ccccc as split output below.

a_string = "aaaaa[x]bbbbb,ccccc";
split_output a_string.split.split(%r{[,|........]+})

what supposed i put as replacement of …….. ?

  • 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-26T00:22:02+00:00Added an answer on May 26, 2026 at 12:22 am

    No need for a regex when it’s just a literal:

    irb(main):001:0> a_string = "aaaaa[x]bbbbb"
    irb(main):002:0> a_string.split "[x]"
    => ["aaaaa", "bbbbb"]
    

    If you want to split by “open bracket…anything…close bracket” then:

    irb(main):003:0> a_string.split /\[.+?\]/
    => ["aaaaa", "bbbbb"]
    

    Edit: I’m still not sure what your criteria is, but let’s guess that what you are really doing is looking for runs of 2-or-more of the same character:

    irb(main):001:0> a_string = "aaaaa[x]bbbbb,ccccc"
    => "aaaaa[x]bbbbb,ccccc"
    irb(main):002:0> a_string.scan(/((.)\2+)/).map(&:first)
    => ["aaaaa", "bbbbb", "ccccc"]
    

    Edit 2: If you want to split by either the of the literal strings "," or "[x]" then:

    irb(main):003:0> a_string.split /,|\[x\]/
    => ["aaaaa", "bbbbb", "ccccc"]
    

    The | part of the regular expression allows expressions on either side to match, and the backslashes are needed since otherwise the characters [ and ] have special meaning. (If you tried to split by /,|[x]/ then it would split on either a comma or an x character.)

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

Sidebar

Related Questions

Trying to get the highest and lowest value from an array that I know
I am trying to get an array of a date plus the next 13
I'm trying to get an array of all elements with the class sampleclass. For
Trying to get a value out of 2d array inside of a hash and
I'm trying to get the values from a pointer to a float array, but
I'm trying to get from an Android Uri to a byte array. I have
I'm trying to make a dynamic array in C# but I get an annoying
I'm trying to build up a string array in JavaScript and get the results
Trying to get some movies and their genres but leave out any records that
i have a webservice and implementing that ,but when i get the array from

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.