My problem is that I've created a very long and unreadable regex to check if a particular input is well-formed.
My regex: ^([0-9]+(\.[0-9]{1,2})?\|([A-Z]{2}((\+([0-9]+(\.[0-9]{1,2})?))?(\*([0-9]+(\.[0-9]{1,2})?))?|(\*([0-9]+(\.[0-9]{1,2})?))?(\+([0-9]+(\.[0-9]{1,2})?))?),)*[A-Z]{2}((\+([0-9]+(\.[0-9]{1,2})?))?(\*([0-9]+(\.[0-9]{1,2})?))?|(\*([0-9]+(\.[0-9]{1,2})?))?(\+([0-9]+(\.[0-9]{1,2})?))?)( \"([^\"])+\")?)$
This isn't readable, and it is very easy to forget what it does...
Is there a way to define a "variable" and use it multiple times in the regex? For example if I define [0-9]+(\.[0-9]{1,2})?
as #number#
my regex would be more readable:
^(#number#\|([A-Z]{2}((\+(#number#))?(\*(#number#))?|(\*(#number#))?(\+(#number#))?),)*[A-Z]{2}((\+(#number#))?(\*(#number#))?|(\*(#float_number#))?(\+(#number#))?)( \"([^\"])+\")?)$