Reputation: 49
I'm trying to remove semicolons from the end of matches inside a string
so:
var ourstring = " (1); (2);; (3) ; (4) ;; (5) ; ; (6); ; (7); ;; (8)";
become:
(1) (2) (3) (4) (5) ; (6) ; (7) ;; (8)
The problem is i don't know how to do that. I have tried to use regular expressions: \s*(?=[;*])[;]+(?!\s)?/g
inside replace, but did not get the wanted results. Please show me how to do that in plain javascript
Upvotes: 1
Views: 525
Reputation:
I guess this is what you want.
var ourstring = " (1); (2);; (3) ; (4) ;; (5) ; ; (6); ; (7); ;; (8)";
var re = /\)\s*;+/g;
var result = ourstring.replace(re, ")");
console.log(result);
It removes zero or more spaces followed by one or more adjacent semicolons that come directly after a closing parenthesis.
Upvotes: 5