0

I am new on regex. Why is my regex not working? /A/gi, "z" && /B/gi, "x" && /C/gi, "y" && /D/gi, "a"

let convertedVal = TextValue1.replace(/A/gi, "z" && /B/gi, "x" && /C/gi, "y" && /D/gi, "a");

I want to convert "A" to "z" and "B" to "x" and "C" to "y" and "D" to a using regex.

But it seems that the and operator "&&" is not working.

Thank you.

  • what exactly are you trying to achieve here? – DecPK Dec 03 '21 at 02:28
  • I want to convert A to z and B to x and C to y and D to a using regex. Thank you. – helpthenoob Dec 03 '21 at 02:29
  • JS doesn’t work this way. Replace every `&&` by `).replace(`. Where did you get the idea that this could ever work? Read the documentation, please: [`replace`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String/replace), [`&&`](//developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/Logical_AND). – Sebastian Simon Dec 03 '21 at 02:30

0 Answers0