I'm trying to figure out the right regex to get the output as expected. It's a part of a bigger problem, and I'm stuck right here. I only want the array elements with the dot(.) notation in them and in the second part after the dot, if there is a symbol (@) group that separately as well.
(Input) arr = ["ab", "cd.ef", "gh.ij@kl"]
(Expecting) [["cd", "ef"], ["gh", "ij", "kl"]]
I have tried the following regex's to achieve this:
arr.join(",").scan(/(\w+)\.(\w+)@?(\w+)/) gives me [["cd", "e", "f"], ["gh", "ij", "kl"]]
Also, tried this:
arr.join(",").scan(/(\w+)\.(\w+)@(\w+)/) gives me ["gh", "ij", "kl"]]
Could someone please provide some guidance on how to get the expected outcome?
/(\w+)\.(\w+)@?(\w+)/is causing it to capture the "f" separately so that it matches the pattern if you make that last capture group optional/(\w+)\.(\w+)@?(\w+)?/you will get[["cd", "ef", ""], ["gh", "ij", "kl"]]