Skip to main content
This is originally a Swift question.
Link
InSync
  • 8.6k
  • 4
  • 12
  • 42
don't denote edits. if one cares about the history, they can look it up in the edit history https://meta.stackexchange.com/a/127655/316262
Source Link
Neuron
  • 5.6k
  • 5
  • 42
  • 61

I need to capture multiple groups of the same pattern. Suppose, I have the following string:

HELLO,THERE,WORLD

And I've written the following pattern

^(?:([A-Z]+),?)+$

What I want it to do is to capture every single word, so that Group 1 is : "HELLO", Group 2 is "THERE" and Group 3 is "WORLD". What my regex is actually capturing is only the last one, which is "WORLD".

I'm testing my regular expression here and I want to use it with Swift (maybe there's a way in Swift to get intermediate results somehow, so that I can use them?)

UPDATE: I don't want to use split. I just need to now how to capture all the groups that match the pattern, not only the last one.

I need to capture multiple groups of the same pattern. Suppose, I have the following string:

HELLO,THERE,WORLD

And I've written the following pattern

^(?:([A-Z]+),?)+$

What I want it to do is to capture every single word, so that Group 1 is : "HELLO", Group 2 is "THERE" and Group 3 is "WORLD". What my regex is actually capturing is only the last one, which is "WORLD".

I'm testing my regular expression here and I want to use it with Swift (maybe there's a way in Swift to get intermediate results somehow, so that I can use them?)

UPDATE: I don't want to use split. I just need to now how to capture all the groups that match the pattern, not only the last one.

I need to capture multiple groups of the same pattern. Suppose, I have the following string:

HELLO,THERE,WORLD

And I've written the following pattern

^(?:([A-Z]+),?)+$

What I want it to do is to capture every single word, so that Group 1 is : "HELLO", Group 2 is "THERE" and Group 3 is "WORLD". What my regex is actually capturing is only the last one, which is "WORLD".

I'm testing my regular expression here and I want to use it with Swift (maybe there's a way in Swift to get intermediate results somehow, so that I can use them?)

I don't want to use split. I just need to now how to capture all the groups that match the pattern, not only the last one.

edited tags
Link
Wiktor Stribiżew
  • 621.4k
  • 39
  • 480
  • 596
Updated the details
Source Link
phbelov
  • 2.5k
  • 3
  • 19
  • 15
Loading
Edited the input string.
Source Link
phbelov
  • 2.5k
  • 3
  • 19
  • 15
Loading
Source Link
phbelov
  • 2.5k
  • 3
  • 19
  • 15
Loading