8
u/survivalking4 Oct 21 '20
This might have been programmatically generated. I mean I hope it is for humanity's sake
3
u/GandelXIV Oct 21 '20
No it wasnt.
10
399
u/n3wsw3 Oct 21 '20
This is why people think they are afraid of regex. This monstrosity can be boiled down to "\w{5,12}"
10
u/evolseven Oct 21 '20
Yah, I love regex.. even back-references aren’t that hard once you get a clear grasp on it. Even reading it is not terribly difficult once you get it.. but, Perl is also my preferred language so I may just be a masochist that likes magic..
17
u/robin_888 Oct 21 '20
Do you know https://regexcrossword.com/?
4
u/Ali3nat0r Oct 22 '20
There go 2 hours of my life while I learn and practice regex. Sad thing is, I'll probably forget most of it by next week...
1
0
Oct 21 '20
[deleted]
215
u/crunchyintheory BuddyPress Oct 21 '20
How about
[a-zA-Z0-9]{5,12}?10
u/danbulant Oct 21 '20
I actually prefer this over \w - it's descriptive enough so even those who have just basic understanding yet don't know what some shortcuts are can see what it does just by looking at it
5
u/new2bay Oct 21 '20
Bingo. The OP looks like it was written by someone traumatized by a DFA in college.
7
u/ywBBxNqW Oct 21 '20
That's probably just fine if you assume that the only allowed characters are those in that code snippet. It doesn't take Unicode into account at all though but maybe that's fine for OP.
1
Feb 02 '21
How would you recommend learning / memorizing regex? It seems really useful, I just don’t know where to start
1
u/crunchyintheory BuddyPress Feb 02 '21
Hm, I'd try to develop an application with some practical applications for regex. I first learned it when developing a URL-detection algorithm as a component of a larger project, and then I added to that knowledge every time I ran into a pattern-matching problem.
1
Feb 02 '21
I can do that. I’m trying to make a thing that converts from discord’s markdown to Minecraft’s JSON RAW format, so that seems like an excellent use for regex...
0
Oct 21 '20
[deleted]
53
u/Farsqueaker Oct 21 '20
Not portable that way, though.
27
u/OnlySeesLastSentence Oct 22 '20
If you can't fit like 20 characters on a drive, you need a bigger drive.
8
u/crunchyintheory BuddyPress Oct 21 '20
TIL, does that work outside of pcre?
33
u/ywBBxNqW Oct 21 '20
It's entirely dependent on the implementation of the regex utility/library you use.
80
u/Beanalby Oct 21 '20
I think this entire thread has shown *THIS* is why people are afraid of regex.
32
u/mfb- Oct 21 '20
All the standard things are independent of the implementation (excluding some obscure corner cases).
Something that doesn't understand
[a-zA-Z0-9]{5,12}is not worth using.15
u/xigoi Oct 21 '20
However, even
\wis implementation-dependent (sometimes it matches non-ASCII letters, sometimes not).4
2
3
u/ywBBxNqW Oct 21 '20
I think the entirety of these comments show that people hold mixed views about regular expressions for whatever reasons.
2
0
16
u/Zentrosis Oct 21 '20
Regex is just like any other code. Complicated if you don't understand it, or if it's too long 🤷🏼♂️
8
u/ywBBxNqW Oct 21 '20
You could argue that there are a lot of things that seem complicated if you don't understand them. :)
0
50
u/veryusedrname Oct 21 '20
Where is our image translating volunteer?
83
u/Zelphy712 Oct 21 '20 edited Oct 21 '20
verify_username_regex = """ ((a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) (a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) (a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) (a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) (a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9) ?(a|b|c|d|e|f|g|h|I|j|k|l|m|o|p|q|r|s|t|u|v|w|x|y|z|A|B|C|D|E|F|G|H|I|J|K|L|M|N|O|P|Q|R|S|T|U|V|W|X|Y|Z|0|1|2|3|4|5|6|7|8|9)) """hi I'm a volunteer only for this post, I don't super know how reddit formatting works and Im on mobile so if it's bad I'll figure out how to fix it. enjoy!
18
19
u/StrangePractice Oct 21 '20
I don’t even think the most passionate of volunteers would give this awful code the time of day to give it new life here
13
u/SarcasticCodeBot Oct 21 '20
from string import ascii_lowercase, ascii_uppercase print('verify_username_regex = \"\"\"\n('+'\n'.join([b[0] if a<5 else '?'+b[0] for a,b in enumerate(['('+'|'.join(list(ascii_lowercase)+list(ascii_uppercase)+[str(c) for c in list(range(10))])+')'] for b in range(12))])+')\"\"\"')0
Oct 21 '20
[deleted]
5
u/redditsoaddicting Oct 21 '20
f'...'Am I remebering that right? I know Python has them.
1
u/Kurinoku Oct 22 '20
you mean like raw strings? or string interpolation?
1
u/redditsoaddicting Oct 22 '20
Raw strings, but now that you mention it, f was probably interpolation.
1
1
u/LonelyContext Oct 22 '20
What's wrong with that?
0
Oct 22 '20
[deleted]
1
u/LonelyContext Oct 22 '20
Yeah I mean I guess that’s what happens when code is written by a Bot that also claims to be Sarcastic.
32
21
13
9
14
4
3
3
2
2
u/NOMASAN163 Oct 22 '20
Haha.... I remember my 9 hours of work for a WORKING editor program... with unique and correct spacing between each and every letter
9 hours of work, 947 lines of code.
2
2
0
Oct 21 '20
[deleted]
14
u/Wiwwil Oct 21 '20
Yeah, but from the "art" you need to replace the "a" by "p", "r" by "o", and "t" by "o"
8
2
76
u/GandelXIV Oct 21 '20
This regex checks if the username contains only alphanumeric characters and checks that its length is 5-12 characters.