I’m trying to create a regular expression that will pick the longest of two options from a string.
Either a numeric value up to 15 characters long or a whatever value up to 11 characters long.
So far i have this:
^([0-9]{1,15}|.{1,11})
But for example the string: '7elevenshopfood' gets shortened to '7' because it looks at the first part of the paranthesis. And if I switch it to
^(.{1,11}|[0-9]{1,15})
the string '123456789123456789' gets shortened to '12345678912' since it looks at the first part of the expression again.
Anyone with greater regexp knowledge have an idea?
That is how most regex dialects work, alternations are tested in order they are written and the first matching part will end the search.
In your case you can work around that with something like: