How to standardize Token in a string by making upper case and removing all spaces?

If I have a token in a string but I want to ensure it is only upper case and contains no spaces, how would I do this? Only the token will have the square brackets in the string.

Input Examples:

1) ?n1=v1&n2= [new vs returning]&n3=v3
2) [New vs Returning]&n3=v3
3 [  NEW     VS retur  nin g      ]&n3=v3
4) ?n1=v1&n2= [current url]&n3=v3
5) ?n1=v1&n2= [    CurRent   uR  l  ]&n3=v3

Output Examples:

1) ?n1=v1&n2=[NEWVSRETURNING]&n3=v3
2) ?n1=v1&n2=[NEWVSRETURNING]&n3=v3
3) ?n1=v1&n2=[NEWVSRETURNING]&n3=v3
4) ?n1=v1&n2=[CURRENTURL]&n3=v3
5) ?n1=v1&n2=[CURRENTURL]&n3=v3

Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

leakim971Connect With a Mentor PluritechnicianCommented:
var standardizeToken = function(search) {
     return search.replace(/\[([^\]]*)\]/, function(found) {
            return found.replace(/\s/g,"").toUpperCase();

Open in new window

894359Author Commented:
Hi Leakim,
This doesn't seem to be working for me?
894359Author Commented:
Sorry my mistake! Thanks!
894359Author Commented:
Thanks again!
All Courses

From novice to tech pro — start learning today.