As a little side learning project, I am attempting to implement my own little Regex engine. I've decided to go with compiling Regex expressions into nondeterministic finite automata since that seems to be what a lot of literature suggests, but I'm a little stuck on the actual implementation.
Specifically, I'm trying to figure out how to handle priority between transitions. A state can have multiple transitions, for instance a* will have one ε transition to the end state and one a transition back to itself. * is greedy, so even though the ε transition is always an option, it should "prefer" the a transition back to itself, and only when out of as or when backtracking should the ε transition be traversed. a*? has the same transitions but conversely "prefers" the ε transition since *? is lazy and should only consume input when backtracking.
How would you handle this kind of priority system in practice? I'm currently representing the automata as a graph where each state is a node and each transition an edge.