Looks to me like your regex should work, but it probably can be improved.
Should the match always start at the beginning of the string? (That's a trick question; if you can't make that assumption, the question makes no sense at all.)
Will there ever be more than one semicolon? If so, do you want the non-capturing part to extend only up to the first one, or to the last one?
Should it always end at the end of the string, or do you only want to match up to the period? Can there ever be more than one period?
This minimally changed regex seems to do what you want, and the added anchors will probably improve performance enough to meet your needs:
^(?:.*?;\s*)?(.+)\..*$
This one should be considerably faster; replacing .*
with negated character classes ([^;]*
and [^.]+
) almost completely eliminates backtracking:
^(?:[^;]*;\s*)?([^.]+)
If you're using a regex flavor that supports them, atomic groups and possessive quantifiers can make it even faster:
^(?>[^;]*+;\s*+)?+([^.]++)