] that I need.
[shortcode type="default"] becomes
[shortcode ], whereas I need it to be
[shortcode]. Please note, there are multiple occurrences within the one string as the codes are built-up.
I need to strip out that blank space, if it occurs, before each occurrence of a
] combination. What is the regular expression for this?
You could use a positive lookahead.
str = str.replace(/\s+(?=])/g, "");
If there is a single space and a single occurrence,
.replace(' ]', ']') is sufficient, but you say specifically that there will be more than one, so
.replace(/ ]/g, ']') will do. If there can be more than one space before the closing brace, use:
If appearance of multiple spaces is possible, you should use
\s+, like this:
g at the end of
/.../ does what you're asking for: replacing multiple occurrences in each line.