简体   繁体   中英

Find matching words in file using regex

This is continuation of my previous question: Parse text file with regex , but because I'm creating new expression I don't want to edit that question.

Thanks to Jerry I'm able to find matches but I need to get more complex.

Classes in ExtJS can have requires and mixins section:

Ext.define('Ext.Window', {
    extend: 'Ext.Panel',
    requires: ['Ext.util.MixedCollection', 'Ext.util.BasicDrag'],
    mixins: {
        draggable: 'Ext.util.Draggable',
        droppable : 'Ext.utils.Droppable'
    }
});

Thanks to previous question I'm able to get extend part, but from above example I would like to get:

Ext.Panel
Ext.util.MixedCollection
Ext.util.BasicDrag
Ext.util.Draggable
Ext.utils.Droppable

Can this all be done using single RegEx? Or maybe 3 different RegEx'es (one from Jerry's answer)

requires section can look as so:

requires: 'Ext.util.MixedCollection'

or

    requires: ['Ext.util.MixedCollection', 'Ext.util.BasicDrag'],

or

    requires: [
               'Ext.util.MixedCollection', 
               'Ext.util.BasicDrag'
              ],

the same with mixins.
Idea behind this is to get all dependencies and build custom minified JS file (I'm aware of Sencha CMD Tool)

I'm able to get single requires but I can't get multiple elements to match. My started regex: http://regexr.com?36hto

Like this?

requires\\s*:\\s*(?:\\[)?\\s*(?:(?:'([^']+)')(?:,\\s*)?)+\\s*(?:\\],?)?

http://regexr.com?36huj

EDIT

requires\\s*:\\s*(?:\\[)?\\s*(?:(?:'(?<inside>[a-zA-Z.]*)')(?:,\\s*)?)+\\s*(?:\\],?)?

That seems to be what you want for named matched

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM