I try to match multiple values between quotes (these values can be anything but spaces) the best I can achieve is to match everything between the first and the last quote
I already checked many SO answers, yet I cannot make it work
here is the regex
\[\[\[(\w*img\w*)\s(\w*id|url\w*)+="([^"]|.*)"\]\]\]
here is the string I try to match (values are numbers but I could have urls or anything similar)
[[[img id="37" w="100" h="70"]]]
I should get all parameters and their respecting values, but I get only one parameter with the value beeing 37" w="100" h="70
I know I am close, but this one is tricky
regards
I don't think you need all the \\w
. And I also would suggest splitting the task in two parts as suggested in a comment.
However, I also see an option in doing it in just one step :
\[\[\[img(?:\s(\w+)="([^"]+)")?(?:\s(\w+)="([^"]+)")?(?:\s(\w+)="([^"]+)")?\]\]\]
This is basically the wrapper [[[]]]
, a normal character part img
and then (?:\\s(\\w+)="([^"]+)")?
repeated as many times as you expect attributes to appear. (\\w+)
matches the name of the attribute and ([^"]+)
its value.
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.