This question is not very clear, but the macek sentence really answers your question about how to add the optional '#' tag, followed by a certain number of digits at the end, so you should try this. (In particular, (?:#\d+)?$ Is the corresponding part of the regular expression; (?:#\d{0,5})?$ Will ensure the presence of 0 to 5 digits.)
However, your regular expression is to ensure that there is exactly 1 space and no more than 12 digits before the "#" option is incorrect. A view, as written, is pointless because \d{0,11} will correspond to a line of width 0 at the beginning of any line (since this is equivalent to 0 digits). You need something like /^(?:[\d\s]{1,13}$)\d*\s\d*$/ . This will be checked to make sure that there is the correct number of characters, and that they are all numbers or spaces, and then checks for only one space per line. There is a bit of redundancy here, but that should not be a problem. Also note that I use \s instead of a space character for clarity, but note that this will correspond to tabs and other spaces that may not be what you want. The number of digits {1,13} suggests that the line should consist of one space without any numbers, but an empty line is illegal; adjust the values โโin parentheses if this is a false assumption.
Finally, to combine the above regular expression to ensure the correct number of spaces and digits with the regular expression for the optional tag, you will need to change the lookahead so that it matches # , as well as $ : it should be /^(?:[\d\s]{1,13}(#|$))\d*\s\d*(#\d{0,5})?$/ .
(Note that I have not actually tested the regex above, so Iโm not 100% sure that (#|$) in the middle will work with all implementations. If itโs not, you can replace it with redundant (#\d{0,5})? )
source share