1. Computer problem? Tech Support Guy is completely free -- paid for by advertisers and donations. Click here to join today! If you're new to Tech Support Guy, we highly recommend that you visit our Guide for New Members.

Javascript replace parenteses

Discussion in 'Software Development' started by L3v3L, Apr 4, 2010.

Thread Status:
Not open for further replies.
  1. L3v3L

    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
     
  2. andythepandy

    andythepandy

    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
     
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 733,556 other people just like you!

Thread Status:
Not open for further replies.

Short URL to this thread: https://techguy.org/914674

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice