I want to process some text to remove any substrings in square brackets, e.g. converting this:
We noted that you failed to attend your [appointment] last appointment . Our objective is to provide the best service we can for our patients but [we] need patients’ co-operation to do this. Wasting appointments impedes our ability to see all the patients who need consultations. [If] you need to cancel an appointment again we would be grateful if you could notify reception in good [time].
To this:
We noted that you failed to attend your last appointment . Our objective is to provide the best service we can for our patients but need patients’ co-operation to do this.Wasting appointments impedes our ability to see all the patients who need consultations.you need to cancel an appointment again we would be grateful if you could notify reception in good.
How can I achieve this?
Use this regex....
var strWithoutSquareBracket = strWithSquareBracket.replace(/\[.*?\]/g,'');
The regex here first matches [
and then any character until a ]
and replaces it with ''
Here is a demo
Check this, it will help you:
var strWithoutSquareBracket = "Text [text]".replace(/\[.*?\]/g, '');
alert(strWithoutSquareBracket);
Fiddle Here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With