python – Regex ‘priorities’ for searching and groups?

Is it possible to prioritise some search patterns in regex over others when using | OR ? I am trying to retrieve some patterns from several text inputs below , but I can’t get the output I desire

nameAaa

to return (nameA) (aa) as two groups eg ([a-zA-Z])([a-z])

nAme

to return (nAme) ()

nameAABC

to return (name) (A) (ABC)

Can I stack these up as several search patterns with an | symbol, and give priority to one over another ?

Eg the last one would be dependant on the text ending in a [A-Z]{3} preceded by a [A-Z]{1}

Read more here: Source link