RegExp not working

Anyone, especially newbies, asking for help with Photoshop Scripting and Photoshop Automation - as opposed to those contributing to discussion about an aspect of Photoshop Scripting

Moderators: Tom, Kukurykus

undavide

RegExp not working

Post by undavide »

Hi,
the following (everything that starts with a dot is) a match:

Code: Select allvar s = ".DS_Store";
var re = new RegExp(/^\.\w+/);
$.writeln(s.match(re) != null); // true


conversely if I put the expression into a string and build the RegExp with it, it doesn't:

Code: Select allvar s = ".DS_Store";
var exp = "^\.\w+"
var re = new RegExp(exp, i);
$.writeln(s.match(re) != null); // false


Do you have any idea about the why?
Thank you!

Davide Barranca
xbytor

RegExp not working

Post by xbytor »

Code: Select allvar s = ".DS_Store";
var exp = "^\\.\\w+"
var re = new RegExp(exp, i);
$.writeln(s.match(re) != null); // false

-X
undavide

RegExp not working

Post by undavide »

Great! So I need to escape the \.
Thank you very much xbytor,

Davide