Reputation: 1165
I'm looking to split a string (and get all the matches) using a regular expression.
I have the following string:
ppc.goo.gen.heat..jan-17.logo
It should return everything between each .
[0] ppc
[1] goo
[2] gen
[3] heat
[4]
[5] jan-17
[6] logo
So far I have this:
([a-zA-Z0-9-]*)\.
Which matches 0 to 5, but it'll miss off match 6 as it doesn't have a . at the end. I tried using lookahead but I couldn't get it working. Any tips?
Upvotes: 0
Views: 88
Reputation: 2152
Group 1 will be the entry.
(?:^|\.)
Match start of string, or .
([^\.]*)
Match 0 or more non-.
characters(?=\.|$)
Match .
or end of stringUpvotes: 1