在正则表达式中获取组的多个匹配项

I am trying to get attributes from a BBCode using regular expression Lets say I have those strings:

[icons a="1" b='2' c="3"]
[icons d="4" e='5' f="6"]

I need using a regular expression to get matches like this:

[
    {'a', '1', 'b', '2', 'c', '3'},
    {'d', '4', 'e', '5', 'f', '6'}
]

I figured this regular expression:

\[icons[\w\s](?:(\w*)\=["|']([^"|']*))+.*?\]

But it only matches:

[
    {'a', '1'},
    {'d', '4'}
]

How I can match all the attributes?

Also, just to make it more bullet proof, is there a way to match only the quote it found?

[icons a="1"] // GOOD
[icons a="1'] // BAD - But still a match

Regex101

查看全部
douqiao3930
douqiao3930
2015/01/12 13:26
  • regex
  • replace
  • php
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

2个回复