Regex operations on Javascript functions -


i'm trying find function names in javascript , insert following code

var functionname = arguments.callee.tostring().substr('function '.length); functionname = functionname .substr(0,functionname .indexof('(')); console.log(functionname); 

this write name of function console it's called. not having luck this. i've been trying variants of sed.exe:

sed "{/function/ s/$/\var ownname = arguments.callee.tostring().substr('function '.length);ownname = ownname.substr(0,ownname.indexof('('));console.log(ownname);/}" *.js 

this in format sed "/elephant/ s/$/\&castle" *.js

anyone have idea how can send i'm appending next line, rather on same line function? also, how can imlement following (but in sed.exe) avoid anonymous function , eval functions??

grep -eho "^s*function w+" *.js | sort 

thanks help.

adding \n replacement string works gnu sed. changed regex have grep ^[[:blank:]]*function \w\+ sed , changed condition of s statement that, , worked properly. here's whole command in bash syntax:

sed "/^[[:blank:]]*function \\w\\+/ s/\$/\\nvar ownname = arguments.callee.tostring().substr('function '.length);\\nownname = ownname.substr(0,ownname.indexof('('));\\nconsole.log(ownname);\\n/" *.js 

Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -