0

I've notifications system on my app and document title is updating with addition of total number of notifications just like facebook and twitter. I want it to remove number with parantheses just after user's click to a button.

document.title = dc.replace(/\(([^)][\d]+)\)/, "");

this is what I use but it's not working. i'm not that good with regex. All I want to do is replace (10) My Website's Homepage with My Website's Homepageon click.

thanks.

2
  • Your first sentence makes little to no sense. Commented Mar 21, 2014 at 17:02
  • 2
    Define "not working". Do you get an error message? I just tried your code and it works. dc = "(10) My Website's Homepage" document.title = dc.replace(/(([^)][\d]+))/, ""); Commented Mar 21, 2014 at 17:05

2 Answers 2

2

I'm guessing you meant for the [^)] to be a lookahead instead of an actual character, and that the + quantifier is supposed to go outside the parentheses that groups this lookahead to the digit. That is, you're trying to say:

* Find an opening bracket
* Followed by one or more digits that aren't closing brackets
* Followed by a closing bracket

But notice how the second sentence, although valid, is redundant? A digit is never a closing bracket. All you need is therefore:

/\(\d+\)/
Sign up to request clarification or add additional context in comments.

1 Comment

@AliDemirci, check out my answwer
2

This should work.

document.title=dc.replace(/\(\d+\)\s/,"");

Demo:http://jsfiddle.net/x6BKD/

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.