-6

From a given string I want an array of all the substrings within the parenthesis of given string for example I have a string

COUNTER_SUM(lehr_in) / COUNTER_SUM(feeder) * 100    

Here I have two substrings within the parenthises "lehr_in" and "feeder" so my result should be

["lehr_in", "feeder"]
Asnad Atta
  • 3,855
  • 1
  • 32
  • 49
  • What are `COUNTER_SUM`, `lehr_in`, `feeder`? – sawa Nov 05 '18 at 09:15
  • Where is the regular expression? – sawa Nov 05 '18 at 09:15
  • 1
    Did you mean COUNTER_SUM(lehr_in) / COUNTER_SUM(feeder) * 100 is string? Like so: `"COUNTER_SUM(lehr_in) / COUNTER_SUM(feeder) * 100"` ? And you'd want to catch string between paranthesis? – Surya Nov 05 '18 at 09:21
  • 1
    Possible duplicate of [RegEx to match stuff between parentheses](https://stackoverflow.com/questions/6208367/regex-to-match-stuff-between-parentheses) – Surya Nov 05 '18 at 09:23
  • yes @Surya "COUNTER_SUM(lehr_in) / COUNTER_SUM(feeder) * 100" is a string and I want you guys to help me to write out the regular expression in ruby so that I can get array of substrings from expression with in the parenthesis. Example is given – Asnad Atta Nov 05 '18 at 13:20

1 Answers1

1

There's probably a better way to do this using regexes, but here's what I came up with:

a.split(/[^(]*\(([^)]+)\)[^(]*/).reject(&:empty?)
DjPadz
  • 36
  • 1
  • 4