Find and Replace - brackets to parentheses

I am trying to change brackets around numbers to parentheses.
I have used both Find & Replace and Replace Example.

I believe I have the correct regex to select the bracket, but when I replace them, I get a double parentheses on either side of the number.

[12] becomes ( )12( )

Here’s my code:

// define regex to use...
const findRegex = /\[|\]/g;
// define replacement expression...
const replaceWith = "( )";

// do the replacement...
draft.content = draft.content.replace(findRegex, replaceWith);
draft.update();

Any suggestions on what I am doing wrong, please?

Try this instead.

// define regex to use...
const findRegex = /\[(\d+)\]/g;
// define replacement expression...
const replaceWith = "($1)";

// do the replacement...
draft.content = draft.content.replace(findRegex, replaceWith);
draft.update();

You have been replacing each bracket with two parentheses.

The one I’ve suggested above looks for digits between brackets then replaces that match with the same digits but surrounded by parentheses instead of brackets.

@sylumer That worked! Thanks so much for your help!!

Hi!
Can you help me with an action?
I what to replace all this letters “ă,â,ș” from my draft with the “a,a,s” How can I do it?
THX

Here is an example Strip Diacritics action that will remove various accented and other diacritic characters from the select text.

Its not working for Romaian Diacritics. It does nothing.

Ive one by myself but I belive there is another way. I made by reading from forum. I know nothing in scripting, it is working but is to long i belive

// define regex to use…

const findFirst= /\â/g;
// define replacement expression…
const replaceFirst = “a”;
// do the replacement…
draft.content = draft.content.replace(findFirst, replaceFirst);
draft.update();

// define regex to use…
const findSecond = /\ș/g;
// define replacement expression…
const replaceSecond = “s”;
// do the replacement…
draft.content = draft.content.replace(findSecond, replaceSecond);draft.update();

// define regex to use…
const findTird = /\ă/g;
// define replacement expression…
const replaceTird = “a”;
// do the replacement…
draft.content = draft.content.replace(findTird, replaceTird);draft.update();

// define regex to use…
const findForth = /\ţ/g;
// define replacement expression…
const replaceForth = “t”;
// do the replacement…
draft.content = draft.content.replace(findForth, replaceForth);draft.update();

// define regex to use…
const findCinci = /\î/g;
// define replacement expression…
const replaceCinci = “i”;
// do the replacement…
draft.content = draft.content.replace(findCinci, replaceCinci);draft.update();

// define regex to use…
const findSase = /\ț/g;
// define replacement expression…
const replaceSase = “t”;
// do the replacement…
draft.content = draft.content.replace(findSase, replaceSase);draft.update();

// define regex to use…
const findSapte = /\Î/g;
// define replacement expression…
const replaceSapte = “I”;
// do the replacement…
draft.content = draft.content.replace(findSapte, replaceSapte);draft.update();

// define regex to use…
const findOpt = /\Î/g;
// define replacement expression…
const replaceOpt = “I”;
// do the replacement…
draft.content = draft.content.replace(findOpt, replaceOpt);draft.update();

// define regex to use…
const findNoua = /\Ț/g;
// define replacement expression…
const replaceNoua = “T”;
// do the replacement…
draft.content = draft.content.replace(findNoua, replaceNoua);draft.update();

// define regex to use…
const findZece = /\Ș/g;
// define replacement expression…
const replaceZece = “S”;
// do the replacement…
draft.content = draft.content.replace(findZece, replaceZece);draft.update();

// define regex to use…
const findUnspe = /\ş/g;
// define replacement expression…
const replaceUnspe = “s”;
// do the replacement…
draft.content = draft.content.replace(findUnspe, replaceUnspe);draft.update();

// define regex to use…
const findDoispe = /\Ş/g;
// define replacement expression…
const replaceDoispe = “S”;
// do the replacement…
draft.content = draft.content.replace(findDoispe, replaceDoispe);draft.update();