Photoshop: ExtendScript Regular Expression bad parse

  • 2
  • Problem
  • Updated 4 months ago
  • (Edited)
ExtendScript Toolkit (and other extendscript-powered environments including photoshp) incorrectly parse regular expressions starting with an equals sign.

We discovered this bug when trying to import a shim with the following line:

str.replace(/=+$/,"")
The error message is "/= does not have a value", so my best guess is ES thinks that's an division assignment and is expecting a number after it (like `var x = 3; x /= 2;`)

We can work around the problem with the new RegExp form: `new RegExp("=+$")` works.

Context: https://github.com/SheetJS/js-xlsx/issues/603
Photo of Sheet JS

Sheet JS

  • 1 Post
  • 0 Reply Likes

Posted 1 year ago

  • 2
Photo of Kukurykus

Kukurykus

  • 160 Posts
  • 28 Reply Likes
I'm quite good at RegExp, but sometimes I'm tired of making workarounds for complex expressions because that RegEx implemented into ExtendScript works differently than should with JavaScript :(
(Edited)