I want to find all strings looking like [!plugin=tesplugin arg=dfd arg=2!]
and put them in array. Important feature: the string could contain arg=
uments or NOT(in some cases). and of course there could be any number of arg
's. So the string could look like: [!plugin=myname!]
or [!plugin=whatever1 arg=22!]
or even [!plugin=gal-one arg=1 arg=text arg=tx99!]
. I need to put them all in $str
array items
Here is what i did...
$inp = "[!plugin=tesplugin arg=dfd!] sometxt [!plugin=second arg=1 arg=2!] 1sd";
preg_match_all('/\[!plugin=[a-z0-9 -_=]*!]/i', $inp, $str);
but $str[0][0]
contains:
[!plugin=tesplugin arg=dfd!] sometxt [!plugin=second arg=1 arg=2!]
instead of putting each expression in a new array item.. I think my problem in regex.. but can't find one. Plz help...
The last ]
needs to be escaped and the -
in the character class needs to be at the start, end, or escaped. As is it is a range of ascii characters between a space and underscore.
\[!plugin=[a-z0-9 \-_=]*!\]
Regex101 Demo: https://regex101.com/r/zV4bO2/1
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.