简体   繁体   English

使用正则表达式在文件中查找匹配的单词

[英]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. 这是我上一个问题的延续: 使用regex解析文本文件 ,但是因为我正在创建新表达式 ,所以我不想编辑该问题。

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: ExtJS中的类可以具有require和mixins部分:

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: 由于前面的问题,我能够得到extend一部分,但是从上面的示例中,我想得到:

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

Can this all be done using single RegEx? 可以使用单个RegEx完成所有操作吗? Or maybe 3 different RegEx'es (one from Jerry's answer) 或3种不同的RegEx(一种来自Jerry的答案)

requires section can look as so: require部分可以如下所示:

requires: 'Ext.util.MixedCollection'

or 要么

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

or 要么

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

the same with mixins. 与mixins相同。
Idea behind this is to get all dependencies and build custom minified JS file (I'm aware of Sencha CMD Tool) 这背后的想法是获取所有依赖关系并构建自定义的缩小的JS文件(我知道Sencha CMD Tool)

I'm able to get single requires but I can't get multiple elements to match. 我能够获得单个requires但我无法匹配多个元素。 My started regex: http://regexr.com?36hto 我开始的正则表达式: http: //regexr.com? 36hto

Like this? 像这样?

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

http://regexr.com?36huj 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 这似乎是您想要的命名匹配项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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