Solved: Javascript Regex (CS2 .jsx)

J
Posted By
jashmenn
Nov 21, 2005
Views
1533
Replies
0
Status
Closed
I was having a hard time trying to figure out the specifics of PS CS2 ..jsx regex format. I kept getting a syntax error, but I finally figured it out an I thought I’d share my thoughts here.
Here are a few things I tried that were wrong:
—–
var reg = new RegExp("*", "i"); // <– syntax error —–
var reg = new RegExp();
reg.compile("*"); // <– syntax error (also tried ‘ reg.compile("*", "g"); ‘ )
——
Short-style regex’s do not give a syntax error, like this: var reg = /lar.y/i; // <– no problem

So If you were, say, trying to add the rollover name inbetween ‘name’ and ‘.suffix’ you could try something like this:

var oname = "grandma.jpg";
var reg = /^(.*?)\.(.*?)$/;
var m = reg.exec(oname);
var newname = m[1] + "_over." + m[2];
alert(newname); // "grandma_over.jpg"

-Nate Murray http://www.natemurray.com

How to Master Sharpening in Photoshop

Give your photos a professional finish with sharpening in Photoshop. Learn to enhance details, create contrast, and prepare your images for print, web, and social media.

Related Discussion Topics

Nice and short text about related topics in discussion sections