regex js for application [0] .customer_id

时间:2017-12-01 11:04:39

标签: javascript regex

我想知道如何用正则表达式获得这3个元素; 尽管知道非常基本的正则表达式,但当我遇到问题时

表达式有3个部分:

应用[0] .customer_id

  1. 申请(在[
  2. 之前)
  3. []
  4. 中的数字0
  5. 字符串在[]
  6. 之后

    我试过这个:

    class GroupScreen(Screen):
        groupName = ObjectProperty(None)
        popup = ObjectProperty(None)
        abc = ObjectProperty(None)
    
        def display_groups(self, instance):
            self.abc    =   10
            print(self.abc)
            if len(instance.text) > 0:
                self.popup = TreeviewGroup(self.abc)
                self.popup.open()
    
    class TreeviewGroup(Popup):
        treeview = ObjectProperty(None)
        tv = ObjectProperty(None)
    
        def __init__(self, **kwargs):
            super(TreeviewGroup, self).__init__(**kwargs)
            self.tv = TreeView(root_options=dict(text=""),
                               hide_root=False,
                               indent_level=4)
    
    
            cur.execute("SELECT * FROM `test` WHERE `id`=?", (abc,))
            rows = cur.fetchall()
            print(rows)
            # rows = [(1, 'test1'), (2, 'test2'), (3, 'test3')]
            tree = []
    
            for r in rows:
                tree.append({'node_id': r[1], 'children': []})
            for branch in tree:
                populate_tree_view(self.tv, None, branch)
            self.remove_widgets()
            self.treeview.add_widget(self.tv)
    
        def remove_widgets(self):
            for child in [child for child in self.treeview.children]:
                self.treeview.remove_widget(child)
    

    但它不起作用。

1 个答案:

答案 0 :(得分:0)

使用群组(),然后您可以从matchreplace返回每个群组。



var str = "application[0].customer_id";

var found = str.match(/(\w+)\[([0-9]+)\]\.(\w+)/);

console.log(found[1])
console.log(found[2])
console.log(found[3])