jQuery replace brackets in title

228 views Asked by At

I'm looking to strip out some contents from the page <title> on click with JavaScript.

Before: (1) Hello World (value in brackets can change)

After: Hello World

What would be the best document.title.replace() regex to capture this (1) part (with a space after it)?

1

There are 1 answers

0
Ahmed On
document.title.replace(/\(\d+\)\s/, '')

So this matches a string starting with a (, then one or more of a digit, then ) and finally a space. This will match (1) or even (556).