Reputation: 11764
Code:
strx = "exam/unwanted_tex/ple";
strx = strx.replace(/\/.+\//, '');
alert(strx); // Alerts "example"
2 quick questions:
Upvotes: 0
Views: 1368
Reputation: 2177
Yes
'*'
and '+'
are called quantifiers. '*'
matches the character or group that precedes it zero or more times. In a sense, this makes the match optional. '+'
matches the character or group that precedes one or more times. In your particular example there is no practical difference. However, when used in other applications the distinction is very important. Here is an example:
'*'
Quantifier (match zero or more times)
// Match 'y' in Joey zero or more times
strx = "My name is Joe";
strx = strx.replace(/Joey*/, 'Jack');
alert(strx) // Alerts "My Name is Jack"
'+'
Quantifier (match one or more times)
// Match 'y' in Joey one or more times
strx = "My name is Joe";
strx = strx.replace(/Joey+/, 'Jack');
alert(strx) // Alerts "My Name is Joe"
Upvotes: 1
Reputation: 5071
.*
means: .
match any single character, *
zero or more times,
.+
means: .
match any single character, +
one or more times
Upvotes: 1
Reputation: 7018
Upvotes: 0