Using Ruby I am parsing strings looking like this:
A type with an ID...
[Image=4b5da003ee133e8368000002]
[Video=679hfpam9v56dh800khfdd32]
...with between 0 and n additional options separated with @...
[Image=4b5da003ee133e8368000002@size:small]
[Image=4b5da003ee133e8368000002@size:small@media:true]
In this example:
[Image=4b5da003ee133e8368000002@size:small@media:true]
I want to retrieve:
Right now using this regex:
(\[([a-zA-Z]+)=([a-zA-Z0-9]+)(@[a-zA-Z]+:[a-zA-Z]+)*\])
I get...
What am I doing wrong? How can I get what I want?
PS: All the results are copied from http://rubular.com/ which is nice to debug regex. Please use it if it can help you help me :)
Edit : if it's impossible to get all options separated, how could I get this:
Edit:
Ruby's Regex implementation seems not to support multiple captures on one group, as most other regex engines do. Therefore, you'll have to do two steps; first getting all the @*:* in one string and then split those.
To get all of them, this should work:
(\[([a-zA-Z]+)=([a-zA-Z0-9]+)((?:@[a-zA-Z]+:[a-zA-Z]+)*)\])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With