Javascript replace parenteses

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

L3v3L

Thread Starter
Joined
Feb 25, 2010
Messages
5
New to javascript, having trouble getting my head around regex, so to get my replace method working

I have this string:
John Doe (1986)

and i want to select the parentheses and the text inside it to exclude it and get this final string:
John Doe

any ideas?

thanks in advance :D
 
Joined
Jul 2, 2006
Messages
379
Hi,
Instead of using replace, use split like this:
Code:
var str = "John Doe (1986)";
var result = str.split(/[(]/, 1);
alert(result);
The /[(]/ simply means look for the opening parenthesis, and the 1 means stop looking after a parenthesis has been found.

Hope this helps,
Andy
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Members online

Top