samedi 12 novembre 2016

Specific pattern to match and extract info from string

I need to be able identifying over a string if it matches with the following patterns:

':module-name' || 'com.example.ClassName' || ':module-name:com.example.ClassName' || 'http://url';

I need to identify if the string matches one of the above patterns, lets split them into 3 groups (urls, local & none) where a url stands for a valid url string. In the other hand local must be in 3 different variants (':module-name' || 'com.example.ClassName' || ':module-name:com.example.ClassName') if this is the case I need to extract the module and component names.

The module name must be a valid nodejs package name and the component name must be a valid Class name (I got the valid class name already covered with this RegExp: /^@?[a-z_A-Z]\w+(?:.@?[a-z_A-Z]\w+)*$/).

What I need is a way to identify where the string belongs to one of the groups (url, local or none) and in case of local, extract the module and component name. The best for a regular expression solution...

Thanks

Aucun commentaire:

Enregistrer un commentaire