Search code examples
javascriptregexparsingutility

Need a way to extract string constants from source code


I need to do the following:

  • extract the strings, obviously
  • ignore comments in source code, // and multi-line /* ... */
  • handle quotes within strings: 'But he wasn\'t here!', "It just won't \"do it\"!"

I was trying to come up with something using grep, but I'm having trouble with quotes within quotes and multi-line comments. I think this is beyond what grep can do.


Solution

  • Look at xgettext also xgettest-js - it should do what you're looking for!