[RESOLVED]Find text on JS file

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

value:function()

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.

$('*:contains("/w+:s*function()")');

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

$('*:contains("function")');

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];
          document.write("("+c1.replace(/</,"&lt;")+")"+"("+c2.replace(/</,"&lt;")+")"+"("+word1.replace(/</,"&lt;")+")"+"("+rbraces1.replace(/</,"&lt;")+")"+"n");
      }

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

http://www.txt2re.com/index-javascript.php3?s=*:function()&14&-15&1&3

Hope this can help you.

Best regards,
Aswecan

Leave a Reply