https://imaginaryctf.org/r/B396-Regular_Reversing_Solution.txt
Step by Step Logic Solution:
First, we want to take the general regex and break it down to all of its component lookaheads. Effectively each lookahead is just a different line in a logic puzzle. As we work through the puzzle, asterisks will indicate a spot we don't know yet.
ictf{
(?=.*4.0.R.G.)
(?=.(?=\d\D{6}\d.+\d{2}\D\d.$))
(?=[}]{42}5}$)
(?=.+\Dn0\D(?:.[A-Z][2-8][A-Z]){1,}.\D4r.[]+$)
(?=.u.{5}u.+ss[n0-5]+})
(?=(?=[NC0-9]{3}\W).(?=[ale]..[n-x301]{10}.{2}$))
(?=[689ABDEFH-MO-QS-Z]{43})
(?=(?:[]+){6}[]+})
(?=[A-Z4]+'[b-w_0-7]++[l-xG_R0-5]+.$)
(?=[C3P0]+4[NSA].[7of9].+[um]+[abc]help{3}})
(?=.+\w\w\dw(?:\d_).(?=.3[r4-9_xp]{3}3\w{2}[15][40].{2}}))
(?=.+\D2.[mango][rum][hooch]+\w\d.{13}\dxp[^xp]{9})
(?=.{5}[ak47].\db\d.++_[D-Z3]{3}[BuMP69][l4ser]{3,6})
.*}$
The very first and very last lines just confirm that we are in the typical ictf format.
First, we can take a look at (?=[^}]{42}5}$) - From here, since it ends with a closing brace and the end of the line we now definitively know the length of the final answer and the last two characters and we can no longer worry about this clue...
ictf{******************************************5}
Next, we now can make sense of (?=[^689ABDEFH-MO-QS-Z]{43}) - this is giving us a large list of characters that appear nowhere in the answer at all... Any of these characters we see in other clues as options can now be ruled out... So let's update the following rules:
(?=[CGNR4]+'[b-w_0-7]++[l-xG_R0-5]+.$)
(?=[C30]+4[N].[7of].+[um]+[abc]help{3}})
This did get us some immediate clarity... we now see that the string must start with [CGNR4]+ and [C30]+ which really means it is one or more capital C and then we know it is followed by 4 and N due to [C30]+4[N]. To further zero-in on the number of C's, we can use (?=[NC0-9]{3}\W) since \W really is a synonym for [^A-Za-z0-9_], we now know that it is one C and is followed by some other punctuation type but not an underscore.
ictf{C4N***************************************5}
The punctuation problem resolves with (?=[A-Z4]+'[b-w_0-7]+ - it now must be an apostrophe since we know the next character is \W. If we take a look at that in conjunction with (?=[C3P0]+4[NSA].[7of9], only 7 is left as a valid fifth character.
ictf{C4N'7*************************************5}
The clue, (?=(?:[]+){6}[]+}), tells us that we have six underscores total, and back to the C3P0 line, we know that one of them is immediately after our current characters.
ictf{C4N'7************************************5}
With the first bit out of the way, we can take a look at the lines that end in $ to see if we can figure out the final word as well. Not counting the 5 we already got, we see the following clauses: .+\d{2}\D\d.$ - [n-x301]{10}.{2}$ - .*\D4r.[^]+$
Since we know the last two characters are 5} we know what the . represents in the first one and what .{2} represents in the second. So the second clause gives us the length of the word and the valid characters within it.
ictf{C4N'7_*************************_**********5}
We knows that it must end with [301][301][n-x]5} when we combine what the two clauses are telling us. Now, if we look at (?=.3[r4-9_xp]{3}3\w{2}[15][40].{2}}) and we can narrow it further to needing to be 3[prx][prx][prx]3[n-x][n-x]10[n-x]5}. We can rule out the 4-9 thanks to 301.
ictf{C4N'7_*********************_33**105}
With more characters filled in, we can start applying more vague lines. (?=.u.{5}u.+ss[n0-5]+}) works great. We know it needs a letter before 5} which now has to be an n. Likewise, the next two letters before that have to be ss. The ss can't fall back any further since we know the first three letters are in the set [xpr]
ictf{C4N'7_*********************_33ss10n5}
We know we still need 4 more underscores and that they can't be in this last word. (?=.+\D2.[mango][rum][hooch]+\w\d.{13}\dxp[xp]{9}) and (?=[C3P0]+4[NSA].[7of9].+[um]+[abc]help{3}}) can help box us in further, thanks to the underscores. We know from the second one, the last three underscores all need at least five letters after them and then the word before that is 3+ characters long. Assuming the bare minimum with what we already know is something closest like this:
~ ictf{C4N'7_____33ss10n5}
Now, those aren't necessarily the positions, but it does mean for the only length of 9 characters that contain no underscores is in the final word. So dxp[xp]{9} must apply to that word and the only valid character in those final three that isn't x or p is an r.
ictf{C4N'7*************************_3xpr3ss10n5}
Moving into the inside, we can take a look at (?=.+\Dn0\D(?:.[A-Z][2-8][A-Z]){1,}.\D4r.[_]+$) which now that we know the full final word, we can walk it backwards. .[]+$ must apply to 3xpr3ss10n5} so 4r has to be the two preceding characters. And (?=[ale]..[n-x301]{10}.{2}$) confirms the letter before that must be [ael]. Since we don't have a place to put a + character yet, +[l-xG_R0-5]+.$ rules out the a and e. This then fully exhausts (?=(?=[NC0-9]{3}\W).*(?=[ale]..[n-x301]{10}.{2}$)) for us and we can choose to no longer look at it.
ictf{C4N'7_**********************l4r_3xpr3ss10n5}
We still have not found our plus sign and we know what every character after it is in the following set: [l-xG_R0-5]. If we consider that with +[D-Z3]{3}[BuMP69][l4ser]{3,6}, we can narrow down what is valid in that second statement... +[GR3]{3}[u][l4ser]{3,6} If we assumed that our current 'l4r' was not part of that last clause, our remaining underscores would not fit into the solution based on our minimum spacing exercise from before. Therefore, we know this second to last word must be 7-10 characters long, the 4th character is u. We also know from our first clue (and knowing that there aren't anymore capital letters to find before the + sign) that there must be at least one R and one G and the R comes first. We could probably make an educated guess at the word at this point, but instead, let's look for something more definitive and cycle back once we can lock in one of these characters.
Our next best attempt at locking in specific positions at the moment is \D2.[mango][rum][hooch]+\w\d.{13}\dxp[xp]{9} - Using ? for our letters and and ! for numbers, it tells us that we have at least...
ictf{C4N'7********????!*********l4r_3xpr3ss10n5} with some amount more letters possibly, a skipped character and then a 2. Since we know our last three underscores have at least 5 characters after them and the one before that has 3+ and that the second to last word has to be 7+ characters long, this actually helps us fill in where the underscores could possibly be... The \w after [hooch]+ has to be one or they no longer fit since we know that none of the underscores can be back to back: ?=(?:[]+){6}[^]+}). In fact, knowing that the second to last word has to be at least 7 characters long and the one before it at least 5, this means they have to be exactly 5 and then 7 characters. Filling in the + and the u we have been waiting for, it gets us to:
ictf{C4N'7*****???_!+_***ul4r_3xpr3ss10n5}
Since we now know the final three underscores, we can see that [um]+[abc][help] and [mango][rum][hooch]+\w\d have to overlap... which gives us m[um]ch! We have now fully applied (?=[C3P0]+4[NSA].[7of9].+[um]+[abc]help{3}}). Since 'much' makes more sense than 'mmch', we can probably assume that is what it is, but we will leave the options open for the moment. Looking back at (?=.+\Dn0\D(?:.[A-Z][2-8][A-Z]){1,}.), we know that we don't have anymore capital letters in the puzzle since '[b-w_0-7]++ completely binds the available characters. Therefore, knowing one R has to come before a G, we can finish the second to last word. Currently, we have no idea where 'n0' will go, but the options are getting more limited.
ictf{C4N'7_***m[um]ch[0-7]+_R3Gul4r_3xpr3ss10n5}
Now, taking stock of the patterns we haven't matched yet... 4.0 - \d\D{6}\d - \Dn0\D - u.{5}u - \w\w\dw(?:\d) - \D2. - [ak47] - \db\d
The \D2. was followed by one of the clues for 'm[um]ch', so we can place that digit. This also matches our digit, six non-digits, and digit. Likewise, there is only one place where we can fit \w\w\dw(?:\d) now...
ictf{C4N'7_??!w_2_m[um]ch_[0-7]***+_R3Gul4r_3xpr3ss10n5}
All six underscores are now in place. 4.0 and \Dn0\D both need to be placed still and since the n is preceded by not a digit, they can't be in the same place. 4.0 can not possibly fit in the first word since it is \w\w\dw. n0 can't fit in the fifth, since 4.0 also has to fit there and only 4 characters are unknown. Since .{5}[ak47] is still outstanding, '[b-w_0-7]+ rules out the a and \D rules out the 47, the first letter must be k
ictf{C4N'7_kn0w_2_m[um]ch[0-7]***+_R3Gul4r_3xpr3ss10n5}
This leaves us still needing to fit 4.0 and \db\d. Since our 4 unknown characters start with a digit and end with a +, the b must go between the two needed digits 4b0. This leaves us with u.{5}u - Our final word must be either 4b0*+ or !4b0+ - The second option means that there would never be a way to make the u 5 characters u work, so the word must be 4b0u+
ictf{C4N'7_kn0w_2_m[um]ch_4b0u+_R3Gul4r_3xpr3ss10n5}
Technically, we still have two options at this point, but only one makes sense - the final answer:
ictf{C4N'7_kn0w_2_much_4b0u+_R3Gul4r_3xpr3ss10n5}