Saturday, 15 August 2015

javascript - Regular expression to extract xgettext function names and params from cli args -


I am working on a CLI app, so that the user can specify an argument with function names with arguments. It actually uses the same syntax as xgettext , such as:

- keyword = __, dgettext: 2, dcgettext: 2, ngettext: 1 , 2, dpgettext2: 2c, 3

I have to find a regedge that breaks it into an array like the following:

  ['__ ',' Dgettext: 2 ',' DCGtextext: 2 ',' Connector: 1,2 ',' DPGtext2: 2C, 3 '];  

How can I do this (for example in JavaScript)?

Even so far what do I have:

  (((? [[[0-9 \ s,]))). ^) [ A-zA-Z_] [A-zA-Z0-9 _] * [:] * ([0-9] * [az] *, *) *)  

Clearly There is a problem in it: it is also capturing a comma every time Any thoughts? How can I leave it?

You can use regex with a regex using positive lookahead like this:

 , ( ? = \ W + gettext)  


No comments:

Post a Comment