ngplayground
ngplayground

Reputation: 21617

How to remove certain part of string

(1) Website Name

(3) Website Name - 08-08-2013 New York City

From the examples above, how would I be able to remove the rounded brackets and the value inside using jQuery or Javascript?

I understand I would be able to get the title from using the code below

var current_title = $(document).attr('title');

Upvotes: 0

Views: 122

Answers (3)

EZLearner
EZLearner

Reputation: 1834

EDIT: Now with more than one digit (or any other characters inside the brackets).

Use:

current_title = current_title.substring(current_title.indexOf(')'));

This should return the rest of the string after the closing bracket.

Check out the function documentation.

Upvotes: 0

Jake Aitchison
Jake Aitchison

Reputation: 1099

var current_title = $(document).attr('title');

current_title = current_title.replace(/^\(\d+\)\s+/,'');

hope this helps

Upvotes: 2

Teneff
Teneff

Reputation: 32158

That's what regular expressions are for. You can try this:

"(3) Website Name - 08-08-2013 New York City".replace(/\(\d+\)/,'')

Upvotes: 2

Related Questions