[RESOLVED]Find text on JS file

I need to find all the text in a JS file which matches the following pattern


for example

1. onPress : function () 
2. doSomething:function()

The value can be any alphanumeric and the function() is
constant, I saw some previous post on SO but I have some  question since I’m not a JS expert…

I’ve tried like following to put the code in the console console (to query the DOM) it’s not working.


or when I try something more general like following I get all the document


Hi MileyH,

Based on your description, you want to find text as “*:function()” . I made a test on my computer as below. You may give it a try.

var txt='*:function()';

      var re1='(.)';	// Any Single Character 1
      var re2='(:)';	// Any Single Character 2
      var re3='((?:[a-z][a-z]+))';	// Word 1
      var re4='(\(.*\))';	// Round Braces 1

      var p = new RegExp(re1+re2+re3+re4,["i"]);
      var m = p.exec(txt);
      if (m != null)
          var c1=m[1];
          var c2=m[2];
          var word1=m[3];
          var rbraces1=m[4];

Alternatively, you can revise it depend on your own requirements. For more information, please refer to the link  below.


Hope this can help you.

Best regards,

Leave a Reply