views:

139

answers:

4

What does /.*=/ mean in the following jquery?

var id=this.href.replace(/.*=/,'');
this.id='delete_link_'+id;
+7  A: 

That's a regular expression that will select all characters before and including an equal sign.

The '.' means any character other than a newline.

The '*' means the character before it can appear any number of times.

The '=' is the regular equals sign.

So any character ('.') any number of times ('*') followed by an equals sign ('=').

Scott Saunders
'.' means any character different to \n, which includes '='Also, * is greedy, so this regex will search for the last =
Null303
+4  A: 

That's a regular expression. The code will replace everything before the '='-sign (and the equal sign) with an empty string. So it will delete the = and everything before it.

My guess is that your url looks something like this http://mysite.com?id=3 then your variable id will contain 3.

Tjofras
And, since the * is greedy by default, it will erase everything up to the rightmost =.
Null303
A: 

The /.*=/ is a regular expression. It replaces any number of characters followed by an equals sign with an empty string.

jonstjohn
A: 

It's a regular expression (or regex).

A regex is a search and replace method which uses pattern matching to locate parts of a string that fit a pattern. (Similar to how a wildcard dir *.* lists all the files in the current directory).

Seth