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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T12:58:56+00:00 2026-05-26T12:58:56+00:00

str1 = M Rahim (C)(W): 61(97)S A Hasan: 51(68) str2 = R Taylor (C):

  • 0
str1 = "M Rahim (C)(W): 61(97)S A Hasan: 51(68)"
str2 = "R Taylor (C): 76(160)B Watling: 16(26)"

puts format(str1) #=> "M Rahim (C)(W): 61(97)\nS A Hasan: 51(68)"
puts format(str2) #=> "R Taylor (C): 76(160)\nB Watling: 16(26)"

for getting these output what I need to do in format() function. I am not much familiar with regular expressions

  • 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-26T12:58:57+00:00Added an answer on May 26, 2026 at 12:58 pm

    This might do the trick but it is hard to know with such a limited sample:

    def format(s)
      s.sub(/\A(.*?:\s*\d+\(\d+\))/) { $1 + "\n" }
    end
    

    The main thing that looks for is ': 61(97)' and ': 76(160)' or, generally, a colon followed by zero or more whitespace characters followed by a number followed by a number within parentheses.

    If you don’t know how many entries are on each line then you can use scan to extract them and join to put them back together:

    def format(s)
      s.scan(/.*?:\s*\d+\(\d+\)/).join("\n")
    end
    

    for example:

    >> s = str1 + str2
    => "M Rahim (C)(W): 61(97)S A Hasan: 51(68)R Taylor (C): 76(160)B Watling: 16(26)"
    >> s.scan(/.*?:\s*\d+\(\d+\)/).join("\n")
    => "M Rahim (C)(W): 61(97)\nS A Hasan: 51(68)\nR Taylor (C): 76(160)\nB Watling: 16(26)"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I wrote the function (defun test () (let ((str1 foo) (str2 bar)) (loop for
I need to search for files which has string str1 appearing before string str2.
I am having a file in the following format Column1 Column2 str1 1 str2
I have just started learning C. void function(char *str1, char *str2) { printf(%p\n, str1);
Ok so i have this javascript function getpreconfigproducts(str1,str2) { var url=ajax_preconfig_products.php?; url=url+id=+str1+&cid=+str2; xmlHttp =
I am comparing two strings, str1 and str2, using the string.compare function in #string.
I need to check whether a string contains another string or not? var str1
string str1(someString); string str2 = string(str1);//how many copies are made here //copy2 = copy1?
String str1 = Test; final String str2 = new String(Test); As we know, the
Assuming I have the following strings: string str1 = Hello World!; string str2 =

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.