What does !$ mean?

Original: /([^.]*)\.(.*)/

Split this as:
[1] ([^.]*) : It says match all characters except . [ period ]
[2] \. : match a period
[3] (.*) : matches any character

so it becomes [1]Match all characters which are not . [ period ] [2] till you find a .[ period ] then [3] match all characters.


/([^.]*)\.(.*)/

Let us deconstruct it. The beginning and trailing slash are delimiters, and mark the start and end of the regular expression.

Then there is a parenthesized group: ([^.]*) The parentheseis are there just to group a string together. The square brackets denote a "character group", meaning that any character inside this group is accepted in its place. However, this group is negated by the first character being ^, which reverse its meaning. Since the only character beside the negation is a period, this matches a single character that is not a period. After the square brackets is a * (asterisk), which means that the square brackets can be matched zero or more times.

Then we get to the \.. This is an escaped period. Periods in regular expressions have special meaning (except when escaped or in a character group). This matches a literal period in the text.

(.*) is a new paranthesized sub-group. This time, the period matches any character, and the asterisk says it can be repeated as many times as needs to.

In summary, the expression finds any sequence of characters (that isn't a period), followed by a single period, again followed by any character.

Edit: Removed part about shortening, as it defeats the assumed purpose of the regular expression.


Anything except a dot, followed by a dot, followed by anything.

You can test regex'es on regexpal


It's a regular expression (it matches non-periods, followed by a period followed by anything (think "file.ext")). And you should run, not walk, to learn about them. Explaining how this particular regular expression works isn't going to help you as you need to start simpler. So start with a regex tutorial and pick up Mastering Regular Expressions.