1

I have a string as follows:

(((154 -10.45, 154 -10, 154.315452 -10, 154.315452 -10.45, 154.0117846 -10.4498789, 154 -10.45)), ((154 -11, 154 -10.9383334, 154.6 -10.9383334, 154.6 -11, 154 -11)))

What I'm wanting to do is to implement an expression which will firstly match the outer brackets, using the comma as the separator thus producing:

154 -10.45, 154 -10, 154.315452 -10, 154.315452 -10.45, 154.0117846 -10.4498789, 154 -10.45

and

154 -11, 154 -10.9383334, 154.6 -10.9383334, 154.6 -11, 154 -11

I'm using the following expression \((.*?)\),* but it still returns the brackets in the matches. I can't quite figure out the pattern needed to match on the last start bracket and first end bracket.

weblar83
  • 681
  • 11
  • 32
  • Thanks, however that still includes the brackets in the match - I want the matches not to include the brackets, just the values between – weblar83 Jul 12 '18 at 08:09
  • 1
    Capture the substring inside, `\(([^()]*)\)` and grab Group 1 value. – Wiktor Stribiżew Jul 12 '18 at 08:12
  • That's perfect - thank you for your help – weblar83 Jul 12 '18 at 08:15
  • is this what you're after? /(-?[0-9]+\.?[0-9]+ -?[0-9]+\.?[0-9]+,? ?+)/ this captures all the numbers – John Jul 12 '18 at 08:28
  • 2
    @John The issue is that `\((.*?)\)` grabs all `(` starting with the leftmost one up to the first `)` ([demo](https://regex101.com/r/dK36tc/1)), while OP needs to start matching with the first *rightmost* `(` to the first `)`. The solution is to use a negated character class [as described here](https://stackoverflow.com/a/51300610/3832970) ([demo](https://regex101.com/r/dK36tc/2)). – Wiktor Stribiżew Jul 12 '18 at 08:32
  • @WiktorStribiżew thank you, think i misunderstood the question, the rightmost made it clearer, thanks – John Jul 12 '18 at 08:36

0 Answers0