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
This might do the trick but it is hard to know with such a limited sample:
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
scanto extract them andjointo put them back together:for example: