简体   繁体   English

如何在RegEx中查找特定模式的许多实例?

[英]How to find many instances of a specific pattern in RegEx?

Currently (in PHP) I have the following regex pattern: 当前(在PHP中)我有以下正则表达式模式:

\[(.*) (.*)=(.*)\]

This matches [doSomething limitation=true] 这符合[doSomething limit = true]

The end result being that my code will interpret that string and replace it with whatever value is coded to return for it. 最终结果是我的代码将解释该字符串,并将其替换为任何编码后返回的值。

However, some of my code needs multiple variables sent through to the function, for example: 但是,我的某些代码需要将多个变量发送给函数,例如:

[doSomething limitation=true otherlimitation=false sendfile=1 title="hello there"] [doSomething限制= true otherlimitation = false sendfile = 1标题=“ hello there”]

How can I make the (. )=(. ) in the regex repeatable so that it matches every variable sent through including the first (most important) name of function? 如何使正则表达式中的(。 )=(。 )可重复,以使其与通过函数发送的每个变量(包括函数的第一个(最重要的)名称)匹配?

The following may work for you: 以下可能适用于您:

\[(.*) ((.*)=(.*))+\]

You may also want to replace your asterisks with plus-signs. 您可能还希望用加号替换星号。 Currently, your regex would match [ =] as a valid string. 当前,您的正则表达式将匹配[ =]作为有效字符串。

\[(.+) ((.+)=(.+))+\]

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

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