I want a regex that will match:
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]
I have this so far :
\[[a-zA-Z]*=[a-zA-Z0-9]*[@[a-zA-Z]*:[a-zA-Z]*]*\]
... but it's not matching all the cases.
\[[a-zA-Z]+=[a-zA-Z0-9]{24}(@[a-zA-Z]+:[a-zA-Z]+)*\]
^ ^
You were enclosing that section with [], which as you are aware, is for a class, you just want a grouping. You should also ensure that the first match has at least one character, and it seems the id block has 24characters always, if this is the case use, {X} to define a repetition of length X.
Shouldn't the additional options be grouped (instead of brackets!) and marked optional (instead of *)? And you should use + instead of * or else an empty string would be matched.
\[[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