简体   繁体   English

正则表达式javascript重复可选部分

[英]Regular Expression javascript repeat with optional sections

Why doesn't this javascript regexp code work? 为什么此javascript regexp代码不起作用? According to the documentation it should: 根据文档,它应该:

Here's my String for parsing (it's the rails nested form information): 这是我解析的String(这是rails嵌套的表单信息):

flex_table[flex_rows_attributes][0][flex_cells_attributes][0][id]

What I want are these sections, which may or may not be part of the string: 我想要的是这些部分,它们可能是也可能不是字符串的一部分:

flex_rows_attributes, 0, flex_cells_attributes, 0

Here's my regular expression(as I mentioned, the javascript flavour): 这是我的正则表达式(正如我提到的javascript风格):

flex_table((\[(\w+)\]\[(\d+)\])*)

I only get back the last of the two entries, but I want them both. 我只返回两个条目的最后一个,但是我都想要它们。

Does anyone know, what I am missing here? 有谁知道,我在这里想念什么?

^(?!flex_table\b).*$|(\[(\w+)\]\[(\d+)\])

Try this.Grab the captures.See demo. 试试看,抓取截图,请看演示。

http://regex101.com/r/hQ9xT1/26 http://regex101.com/r/hQ9xT1/26

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

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