0

I would like to separate a dot delimited string into its component parts using regex.

I can build something that captures the first example, but struggling to find out how to get the pattern to recurse.

The source string is something like

all.cats.like.chicken

I would like the output to be (in this case) four capture groups

1: all
2: cats
3: like
4: chicken

I have this pattern that will return the first and second elements

(/\w*)(?:\.(\w*)) (i.e. 1:all 2:cats)

And this version will return the first and last elements

(\w*)(?:\.(\w*))+ (i.e. 1:all 2:chicken)

How do I modify (or replace!) this to get all the terms?

Thanks in advance for whatever help you can provide.

JCOGS Design
  • 101
  • 1
  • 3
  • Specifically, see [this answer](https://stackoverflow.com/a/59204121/3832970) if all you have is just a regex pattern and no code (the regex will look like [this](https://regex101.com/r/rkxuHz/1) then.) But if you can, simply split with a dot. – Wiktor Stribiżew Apr 20 '21 at 17:26
  • 1
    Thank you! I tried searching for the answer you linked to but did not find it. Your help much appreciated. – JCOGS Design Apr 20 '21 at 17:34

0 Answers0