I need to capture a value based on a pattern match, but also based on a priority. Thinking of an If Then Else.
ABC-10R0349
CBS-19K49
NBC-20R1529
PBS-20-0524
For example I need to return CBS-19K49 or first match using ([a-zA-Z]{3}-[A-Za-z0-9]{5})
if it is available, but if it is not available then return ABC-10R0349 or first match using ([a-zA-Z]{3}-[A-Za-z0-9]{7})
Eventually I may need to add another match such as PBS-20-0524 or first match using ([a-zA-Z]{3}-[0-9]{2}-[A-Za-z0-9]{4})
Can’t quite get what I’m looking for.
(?:(?=[a-zA-Z]{3}-[A-Za-z0-9]{5,}$)?([a-zA-Z]{3}-[A-Za-z0-9]{5})|([a-zA-Z]{3}-[A-Za-z0-9]{7}))
(?=[a-zA-Z]{3}-[A-Za-z0-9]{5}$)([a-zA-Z]{3}-[A-Za-z0-9]{5})$|([a-zA-Z]{3}-[A-Za-z0-9]{7})$
(?=[a-zA-Z]{3}-[A-Za-z0-9]{5,}$)([a-zA-Z]{3}-[A-Za-z0-9]{5}$|[a-zA-Z]{3}-[A-Za-z0-9]{7}$)