Creative COW SIGN IN :: SPONSORS :: ADVERTISING :: ABOUT US :: CONTACT US
Creative COW's LinkedIn GroupCreative COW's Facebook PageCreative COW on TwitterCreative COW's Google+ PageCreative COW on YouTube
ADOBE AFTER EFFECTS:HomeForumBasicsExpressionsTutorialsPodcastsAE TechniquesTrainingCreative Cloud DebateFAQ

strange syntax error with bracket character only

COW Forums : Adobe After Effects Expressions

<< PREVIOUS   •   FAQ   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook
Daniel Crooksstrange syntax error with bracket character only
by on Apr 27, 2011 at 6:49:09 am

hi all

I am having a very strange problem with a script I'm writing.
I'm doing a string search and get a syntax error only if I search for an opening bracket character i.e. "(" . Any other character including the closing bracket, various other symbols, chunks of text works fine...? but any string containing the opening bracket reports an error.
is this a bug ? it's driving me crazy .

doesn't work:
else if (lineData.search(")") != -1){
else if (lineData.search("blah ) blah") != -1){

this does:
else if (lineData.search("(") != -1){
else if (lineData.search("#blah") != -1){

../daniel


Return to posts index
Reply   Like  

Dan EbbertsRe: strange syntax error with bracket character only
by on Apr 27, 2011 at 2:24:22 pm

I can't get it to fail.

This works for me:

lineData ="67890()-=";
if (lineData.search(")") != -1) alert ("yay") else alert ("boo");

Dan



Return to posts index
Reply   Like  

Daniel CrooksRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 12:20:10 am

Dan,
thanks for checking, I can confirm the closing bracket works but try searching for an opening bracket... "(" like this...

lineData ="67890()-=";
if (lineData.search("(") != -1) alert ("yay") else alert ("boo");

I get "unable to execute script at line 2. Syntax error"

???

cheers../daniel


Return to posts index
Reply   Like  


Dan EbbertsRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 12:31:16 am

Ah yes. indexOf() works, like this:


lineData ="67890()-=";
if (lineData.indexOf("(") != -1) alert ("yay") else alert ("boo");


But search() takes a regular expression as a parameter, so you probably have to escape the paren, like this:


lineData ="67890()-=";
if (lineData.search(/\(/) != -1) alert ("yay") else alert ("boo");



Dan



Return to posts index
Reply   Like  

Daniel CrooksRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 12:47:46 am

still no joy !

I thought perhaps there was some kind of escape needed but no, even with the \ in there I still get the syntax error, swap out the ( for an other character and it works... bizarre !?


Return to posts index
Reply   Like  

Dan EbbertsRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 2:21:39 am

Did you try the forward slashes instead of the quotes?

Dan



Return to posts index
Reply   Like  


Daniel CrooksRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 4:42:22 am

sorry, my bad. I copied the code from the email not the cow site... doh.
the (/\(/) worked !!! (even if it does look like ascii art !)

thanks, Dan

but I'm still not sure why the regular expression couldn't handle the "(" when it could handle everything else ?


Return to posts index
Reply   Like  

Dan EbbertsRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 5:24:26 am

Inside a RegExp (like search() and match() use) you should escape (back slash) any of these regexp special characters if you want to match them as literals:


.|*?+(){}[]^$\



Dan



Return to posts index
Reply   Like  

Daniel CrooksRe: strange syntax error with bracket character only
by on Apr 28, 2011 at 6:01:36 am

thanks Dan, really appreciate it !


Return to posts index
Reply   Like  

<< PREVIOUS   •   VIEW ALL   •   PRINT   •   NEXT >>
Share on Facebook


FORUMSTUTORIALSMAGAZINESTOCKYARDVIDEOSPODCASTSEVENTSSERVICESNEWSLETTERNEWSBLOGS

Creative COW LinkedIn Group Creative COW Facebook Page Creative COW on Twitter
© 2013 CreativeCOW.net All rights are reserved. - Privacy Policy

[Top]