javascript - Regex to remove spaces between '[' and ']' -
i have been breaking head on sometime now. in javascript have string expression need remove spaces between '[' , ']'.
for example expression can :-
"[first name] + [ last name ] + calculateage()"
i want become :-
"[firstname] + [lastname] + calculateage()"
i tried following stackoverflow question square brackets didn't quite there. how make regex in question, work square brackets too?
can help?
thanks, aj
if brackets balanced correctly , if never nested, can it:
result = subject.replace(/\s+(?=[^[\]]*\])/g, "");
this replaces whitespace characters if , if there ]
character ahead in string no intervening [
or ]
characters.
explanation:
\s+ # match whitespace characters (?= # if it's possible match following here: [^[\]]* # number of characters except [ or ] \] # followed ]. ) # end of lookahead assertion.
Comments
Post a Comment