PDA

View Full Version : Regex Separator



Jeff Wheeler
July 28th, 2006, 10:40 PM
Alright, I'm sure this is obvious, but I'm looking for a regex which will match any number of times (i.e., once or more, +), but must have a ‘.’ between each one, and not one before or after. I mean, I want it to match test.test, or test.test.test, with, say, ([^.]+) as the pattern matching test.

Clearly I could just do something along the lines of ([^.]+)(\.[^.]+)*. The problem with this, is I had to repeat [^.]+, which in my case, is quite long.

I'm looking for a solution which doesn't require me repeat it… look-ahead assertions and such are no problem, and I'm using the python regular expression syntax (http://docs.python.org/lib/re-syntax.html).

Thanks :)

Jeff Wheeler
July 29th, 2006, 01:45 AM
Ah, I found the simplest solution. I just do a check for either start-of-string (^) or a literal period. :)

((^|\.)[^.]+)+$

Hope it helps somebody in the future.