[Solved] Wrap string in brackets but also having random value in string: [closed]
You can try this: str = str.replace(/\w*\(\d*\)/g, function () {return ‘(‘ + arguments[0] + ‘)’;}); A live demo at jsFiddle EDIT Since you’ve changed the conditions, the task can’t be done by Regular Expressions. I’ve put an example, how you can do this, at jsFiddle. As a side effect, this snippet also detects possible odd … Read more