Not exactly, but I made my own math "library" so each word can go to it's own keyword. They are split into tokens, and the parenthesis get ordered so it runs in the right order. It is used to turn any string math equation into something my terrain generator for Bonk Universe can use. I can now define any variable or function like x, y, sin(), cos(), noise(), chickenSandwitch(), etc
FYI if you're parsing function calls via regex then you can't parse nested parentheses. It is mathematically theoretically impossible to parse nested parentheses properly with regex. You need to use a proper parser grammar.
Matched parentheses can't be distinguished by a regular language. I.e., strings with unmatched parens would also be falsely accepted as valid.
However, most regex-engines are more powerful than "regular expressions" in the formal sense. Using things like back references should be powerful enough.
Theoretically regular bracket strings are not regular, but if we limit the depths to a definite finite number (which indeed actual math expressions are bounded by memory size), then it is regular.
Formally, regular expressions are calculated/equivalent to finite state machines. As the name suggests, they can only encode a finite, predefined set of states, which means that a given RegEx can at most ensure that up to a fixed natural number n opening parentheses can be matched at a time. Any larger amount can either lead to a fail state output or it does not guarantee that they were actually closed.
No, but regexes used in programming languages typically feature backreferences, which might be able to pull this off (Not that they're used in the post of course)
No, the paradox is that people were told "your language's regex library has a DoS vulnerability if you give it hostile regexes and the cause is because they support non-regular features you hardly ever use", and instead of switching to actual regular expressions they added a pattern to security scanners to look for untrusted input being passed to a regex function.
Back in my self taught days, I ran into this problem.
So I made a function that could turn a regex that parses n layers of parentheses into one that parses n+1. If the users made a more complicated input, I generated a more powerful regex.
Latex is is good for presenting mathematics, but it allows you to input complete and utter nonsense and lacks any real ability for programs to actually interact with the underlying concepts. Latex allows the statement "2+2=5" and doesn't have any way to know it's false, and it also allows "()()cos()+^2".
It's as close to a grammar as Reddit comments are.
You can't even parse a mathematical equation with a Regex. Regex evaluate finite state automata which are incapable of counting arbitrary nesting depths and this is Chomsky Hierarchy 101 (checking matched parentheses requires a context free grammar which is type 2 whereas regex is type 3)
And that regex is broken ( "-?" inside the number definition, an expression like x-5 will be tokenized as [Identifier: x] and [Number: -5]).
And if you think this is scary you should have a look at RFC 822/5322 lol
That's why you should pay attention to your formal languages course, kids
2nd one is older and slower, I never really knew why, I just don't know enough about regex ig since that took me 3 days to write. And yeah I meant tokenize mb, it turns it into a token list that my math parser can evaluate. the top one is for Bonk Universe terrain gen, and the bottom one is for putting fractal equations into minecraft
As JWZ said "Some people, when confronted with a problem, think I know, I'll use regular expressions. Now they have two problems"
A DFA probably takes like ~50 loc, is infinitely more readable, always O(n) and never backtracks like most modern regex engines will, since they're complex atrocities meant for occasional usage (or avoided entirely if your goal is performance)
Anyone can learn this at college, or even on the internet. All it takes is curiosity and some effort. What pisses me off sometimes is that people willingly don't pay enough attention to stuff like this (even though I was always fascinated by it).
If you understand regex, you understand automata theory and thus Kleene's Theorem which leads you to theory of computation. With a good enough understanding of automata theory and theory of computation, you can build entire compiler frontends
vt.edu == Virginia Tech (my alma mater), not Vermont.
Some of the folks in the VaTech computing department raised the concern of confusion with Vermont when the university was getting the domain name, the university admin overruled them.
I wasn't saying that. The knowledge in the upthread comment — that this is Chomsky hierarchy 101, that regexes boil down to finite state automata, that finite state automata cannot, by their definition, handle nested parentheses, is also knowledge that you, too, can obtain, and is usually taught either in the fall Sophomore semester, or the spring Freshmen semester of a college degree. (I.e., it is either your second or third class is a CS curricula.) Numerous people go through those classes every year, and they're just normal people, too.
A compsci student here and what you said was indeed very basic stuff any second year student ought to know but for some reason this sort of math-y theoretical part of computerscience is like pulling teeth for many.
I know many competent programmers who struggled and even had to redo the course concerning automata.
I mean, people forget programming is essentially applied mathematics. Automata, state machines, etc. are all math concepts.
You can't really decouple programming from mathematics as a lot of modern programmers seem to think, for some reason. Computers process information everything through mathematical operations (i.e. they compute).
And it's not like it's that complicated, either. You don't need a PhD to be a good programmer, you just need to know the theoretical basics so you can apply them in real life.
They think that because high level languages are abstracted enough that it's not obvious. You don't start writing in python and think, "Oh, this is a series of binary operations." And depending on your early experiences, you may even fail to realize that there is a consistent logic behind a computer's operations. Idk how far you can really get with that framework, but I can promise you that getting through a second year course is possible.
I unironically think that going scratch to C/rust if not assembly over starting with python/js and then moving to java - if that - would sort out a lot of these issues....
But I do think that this is where a distinction between a programmer and a computer scientist becomes apparent. I am not claiming that the later is superior to the former but you really can see the difference.
It's also knowledge I don't know where to learn. I don't have a formal CS education and don't expect to be able to get one. Where can I learn more on this? Are there any publicly available lectures?
I know that MIT has published many of the intro lectures. However, I don't think the scientific, "math-y" understanding is too important for one to be a good programmer.
Having some grasp on if your code is O(n) or O(2n) and why you are using the datastructure of your choice is pretty good, but I don't think you're really losing anything if you don't know what a push down automata is as most practical coding is quite abstracted away from the base principles.
Eh, as long as you know what regexs are and why you would normally want to use one (parsing math expressions is probably not a great use case unless there’s some strong requirements/limits on what is being parsed), you’re most likely fine. The classic examples of matching a phone number, email, address, etc have libraries/stack overflow examples you can copy and for something like going through a log file you can usually google your way through (or asking AI in this day and age) if you find yourself needing to do it.
Don't worry, none of that information will ever come in handy and it was all a bunch of words to say "haha you said parse and that's not the correct word lolol look how smart I am sometimes I go back and look at my old record comments and masturbate".
Your pride in ignorance perfectly explains the miserable state of modern software.
If you think having the intellectual curiosity to learn how stuff really works is useless, you shouldn't have become a programmer. Tokenization and parsing are two completely different concepts, not just interchangeable terms.
if you think that "none of that information will ever come in handy" then you simply don't have the capacity to reason about computing in any way. formal languages are incredibly important and they are the fundamental basis of programming.
I get this is a humor sub, but to be fair there is a massive amount of non-trivial software engineering jobs which will never have to touch this knowledge.
Being curious is nice and all that but let's not pretend it's fundamental in the professional world.
Realistically if you had to work on doing work on math equation's similar to OPs post it would be on you to read up and research what you need on the spot - I can attest that after a relatively successful (so far) career in software engineering those words certainly sparked some memories (and nostalgia) from my studies but it is by no means something I keep in my head or would have remembered otherwise just by seeing OPs post.
In fact, it is a fundamental, 101 CS concept that is intrinsically connected to how computers process syntax. It's not like regex is a low level concept. It's embedded in virtually any database and modern language from JavaScript to Go.
Not understanding regex will eventually lead you to try atrocities when facing text processing problems because you didn't know there was a more elegant way to do it.
Because modern regex engines are so complicated, it is up to you to learn the theory of how it works so you don't DoS your own service (ahem, Cloudflare) or screw up your regexes
Well, anecdotally, I've been working in fraud detection/risk management software for the last three years and I think I've written regex in code twice during this time.
I primarily ever use regex for grepping on VMs, and would be hard pressed to approve a merge request that makes heavy use of it without a good explanation attached.
I think I spent a quarter of this year staring at explain analyze statements, and probably another quarter of it staring at heap and thread dumps.
This falls into the same category as using bitwise operations in my eyes. Can you do some cool tricks? Yes. Will you reduce the readability of your code unless they are very frequently used in your code base? Also yes. Do they rely on things considered fundamentals of the science, but not necessarily the profession? Also also yes.
It's up to the engineer to notice when they are going to use regex (or any technology) to such an extent (or in an important enough place) that they should spend some time researching and simulating what their future solution is going to be.
There are countless deep topics that are central to how computers work, it would be insane for any one person to actually be intimately familiar with even a good percentage of them.
I use this for the terrain generator of Bonk Universe, so it plugs in an x and y position, and whatever the formula is tokenized into and evaluates is used for the height map of the world, so any function or variable can be defined in the surrounding code
years back I tried one for validating email addresses. Learned a LOT about what is considered a valid email address. Decided to only validate what a normie would consider an email address, no complaints yet.
also tried to validate html, every single search result was basically "you should not validate html with regex" tried to prove them wrong, but it turns out they're not wrong.
Regex isn’t the right solution for either of those situations. For email, just about any language has a library that can do validation. For HTML, use a mainstream browser if you can, or find a third-party solution. Otherwise, you’re reinventing the wheel.
The way to validate email is literally just to send the verification email to the address provided. If it's not a valid or active address, the email will bounce back and you can fail the user verification
The worst one was so wild that it required a code to generate it to allow us to maintain it. It was one to extract addresses from raw text out of OCR of invoices. It had to take into account potential OCR errors and unholy address formats.
It worked very well but a real pain to debug and I switched to a cybersecurity career after that.
You didn't specify what kind of address. You can't possibly mean physical addresses because they cannot be normalized and regex have no power over them.
It was physical address and yes you can extract them with unholy regex most of the time.
The regex was right about 85% of the time (we measured it). The 15% remaining were entered manually and used to improve the regex.
To get a high match rate the regex was purposely extracting a few false positive and we get the right one by validating it using GMaps API (they have an endpoint dedicated to it).
This? Scariest? Sweet summer child... I wrote few times longer expressions by hand from scratch, and I'd say I'm not very good at regex and have to lookup to cheat sheet regularly and the largest and most complex expression I ever wrote stands as far from the scariest expression as one billion from Graham number (which, for info, is so large that even if each elemental particle in the Observable Universe would be a number it would only cover a minuscule fraction of numbers in Graham number; it's so large that the previous statement is a ridiculously gross understatement). For starters, have you seen fully RFC 5322 compliant address validation regular expression? And pretty sure that's far from worst.
Upd.: just found one for a mod I've been making. It parses MIPS instruction. Still, it's far from most complex expression I ever wrote, but it's one I could remember where to find.
I know somebody who handwrote one that validated domains, anyway probably this one: /(if\s*\(\s*(_0x[\da-f]+)\s*\[\s*_0x[\da-f]+\s*\(\s*0x[\da-f]+\s*\)\s*\]\s*===\s*\w+\s*\)\s*return\s+void\s+this\s*\[\s*_0x[\da-f]+\s*\(\s*0x[\da-f]+\s*\)\s*\]\s*\(\s*\)\s*;)/ (for patching part of https://geometrydash.com)
There is nothing difficult about these. They both bundle three different types of token. Numbers, variables and operator symbols.
The first one only reads positive numbers, the second one supports negative numbers and e-notation.
Typically, if stuff gets really complex, it's a good sign regex is just the wrong tool. So the most complex regexes are the ones I write for mass search-replace in the editor, where there is no other tool.
I like this one purely because of how much I had to escape in vim, and because it's just so... vertical:
^[^|]*\(([^)]*)\)\(\(.\|\n\)*\1\)\@!
Unescaped (or rather, dropping vim magic for readability):
^[^|]*(\([^)]*\))((.|\n)*\1)@!
Basically, I wanted to match just one instance of each unique tuple that had no pipes before it, like
(a, b, c) |
(a, b) |
(a, b, c) | // no match
... | (a, b, c) | // no match
So, from the start of the line ^, match everything that's not a pipe [^|]*, until we match a parentheses pair \([^)]*\) -- knowing the data inside the tuple wouldn't have ) -- and capture it as group 1 (). Then, check all following characters on all lines (.|\n)*, and if capture group \1 is matched again anywhere, even after a pipe now, this line no longer matches: @!. So, just the last occurrence is matched!
This would have the side effect of not matching anything if the last occurrence were after a pipe, but thankfully that didn't matter for my purposes. Fixing it now, for fun, it'd be something like this:
^[^|]*\(([^)]*)\)\(\(.\|\n\)*^[^|]*\1\)\@!
I wouldn't put the first-pipe-check in the capture group, though, since I'd want to account for there being different whitespace, other characters, etc.; just as long as that tuple is somewhere before the first pipe a second time, it shouldn't match the current line.
The techlead of the company I work for told me to always use regex for validation because it is more readable. I can still read conditional blocks, but I have no idea what the regexes I wrote 6 months ago even do today.
I still reach for regex more than most people I work with because it feels very natural to me now. That said, if I have to do any lookaheads or any of the real nonsense I still need the manual.
Regex can get pretty hairy if you try to cram it all on one line. You can use the enter key, you can add indentation. It become 1000x more readable that way.
I had to inject error handling with parameter logging into about 1000+ visual basic classes and modules. (Into each function/method)
They wanted it for every function that did not yet have its own error handling.
I learned a LOT about the structure of a visual basic file... And in the end I actually made it and the whole thing compiled and did what it was supposed to do. The "regexp" was about 3 screens long, and I am sure it was the main contributor for my hair loss. But I now know the difference between a greedy and a non greedy match and see regexp more like a programming language with a horrible syntax.
I don't even remember but i made one like 51 chars long once for taking html content or possibly just compressing html into a structure where no libraries existed
I wrote a custom parsing, highlighting, and rendering engine as a side-project to help me decompose and keep track of some genuinely nightmare-tier (~200+ LoC) regexen, a very long time ago.
To be clear, not 200 lines of some other language using regular expressions. Individual compound expressions written in their own files to make editing and understanding them easier.
(These were highlighting-engine grammars for a really weird macOS-only code editor back then, named Espresso; I forget most of the details, but I have some cool screenshots buried somewhere of some insanely complex nested regexen.)
I've concluded that regex should almost never be used in production code. It can be handy as a search tool in text editors. However, the number of cases where regex is actually the correct tool for the job (parsing regular languages) is extremely limited. Extending regex with backreferences and other features detaches it from it's theoretical framework and generally has performance issues. Even when used appropriately, regex expressions quickly become a write-only mess with only modest complexity. You're almost always better off using a proper grammar and parser generator than regex.
I don't mean to sound like a jerk but if you are proficient at regexes they are very useful. I use them all them time. There are all sorts of methods (interpolation, regexex with comment, etc.) to demystify what's going on so they can be maintained or extended.
I mean sure, how often do you use them for parsing a true grammar? I've done that maybe once? But they are vastly more powerful than that.
it is already being used for Bonk Universe's terrain generator, it doesnt need an equals sign because it plugs in an x and y position, and whatever the function evaluates is what is used for the height map
429
u/haitei Sep 15 '26
Do math equations even form a regular grammar?
183
u/darthjammer224 Sep 15 '26
Wasnt scary because of the line of regex, it was scary because I was running it in powershell against file and folder names 🫡
259
u/Zinho3311 Sep 15 '26 edited Sep 15 '26
No, they don't parse. They tokenize.
You can't even parse a mathematical equation with a Regex. Regex evaluate finite state automata which are incapable of counting arbitrary nesting depths and this is Chomsky Hierarchy 101 (checking matched parentheses requires a context free grammar which is type 2 whereas regex is type 3)
And that regex is broken ( "-?" inside the number definition, an expression like x-5 will be tokenized as [Identifier: x] and [Number: -5]).
And if you think this is scary you should have a look at RFC 822/5322 lol
That's why you should pay attention to your formal languages course, kids
14
u/TTFH3500 Sep 15 '26
.*
13
u/KrokettenMan Sep 15 '26
Those are super simple regular expressions tho. The fact that they are in a string and double escaped makes them harder to read
Regex haters are literally too lazy to learn. Regular expressions are piss easy
2
u/NotDG04 Sep 16 '26
But i dont see any of those match = sign.. How are those matching equations?
25
u/CachedPotato Sep 15 '26
years back I tried one for validating email addresses. Learned a LOT about what is considered a valid email address. Decided to only validate what a normie would consider an email address, no complaints yet.
also tried to validate html, every single search result was basically "you should not validate html with regex" tried to prove them wrong, but it turns out they're not wrong.
12
u/redheness Sep 15 '26
The worst one was so wild that it required a code to generate it to allow us to maintain it. It was one to extract addresses from raw text out of OCR of invoices. It had to take into account potential OCR errors and unholy address formats.
It worked very well but a real pain to debug and I switched to a cybersecurity career after that.
Edit : Now I master regex, but at what cost
32
u/aberroco Sep 15 '26 edited Sep 15 '26
This? Scariest? Sweet summer child... I wrote few times longer expressions by hand from scratch, and I'd say I'm not very good at regex and have to lookup to cheat sheet regularly and the largest and most complex expression I ever wrote stands as far from the scariest expression as one billion from Graham number (which, for info, is so large that even if each elemental particle in the Observable Universe would be a number it would only cover a minuscule fraction of numbers in Graham number; it's so large that the previous statement is a ridiculously gross understatement). For starters, have you seen fully RFC 5322 compliant address validation regular expression? And pretty sure that's far from worst.
Upd.: just found one for a mod I've been making. It parses MIPS instruction. Still, it's far from most complex expression I ever wrote, but it's one I could remember where to find.
7
u/ldn-ldn Sep 15 '26
The scariest Regex? Definitely an HTML parser in Regex!
5
u/Drodr10 Sep 15 '26
Just recently I did month/day with back referencing to make sure that months only have valid days that match. I didn't like it.
5
u/Z3t4 Sep 15 '26
Pff. I'll leave this here:
https://gist.github.com/baker-ling/3b4b014ee809aa9732f9873fe060c098
5
u/ExcellentEffort1752 Sep 15 '26
To validate a local or UNC directory path, from over a decade ago, it was fun!
3
u/Jonrrrs Sep 15 '26
(y.{2}r|y.{3}r)\s+(m.m|m.{1}m)\b
3
u/Upper_Parsley_9118 Sep 15 '26
(?x)?=(?:[^"']|"[^"]"|'[^']'*$)(?:(?<o>()|(?<-o>))|(?(o)|(?!)))*$(?(o)(?!))
3
u/CrossScarMC Sep 15 '26
I know somebody who handwrote one that validated domains, anyway probably this one:
/(if\s*\(\s*(_0x[\da-f]+)\s*\[\s*_0x[\da-f]+\s*\(\s*0x[\da-f]+\s*\)\s*\]\s*===\s*\w+\s*\)\s*return\s+void\s+this\s*\[\s*_0x[\da-f]+\s*\(\s*0x[\da-f]+\s*\)\s*\]\s*\(\s*\)\s*;)/(for patching part of https://geometrydash.com)3
u/KCGD_r Sep 15 '26
Complete email validation according to the RFC 5322 standard:
/(?:[a-z0-9!#$%&'*+\x2f=?^_\\x7b-\x7d~\x2d]+(?:.[a-z0-9!#$%&'+\x2f=?^_`\x7b-\x7d~\x2d]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")@(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])).){3}(?:(2(5[0-5]|[0-4][0-9])|1[0-9][0-9]|[1-9]?[0-9])|[a-z0-9\x2d][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])/`3
u/EndMaster0 Sep 16 '26 edited Sep 16 '26
This is scary not because it's complicated but because this was being used to read a specific column of a .csv file
2
u/MasterGeekMX Sep 15 '26
It was one to check if a given text had the structure of a roman numeral and it was written properly.
Here it is: https://www.reddit.com/r/ProgrammerHumor/s/OR2Ov2sr9h
2
u/_damax Sep 15 '26
(([1-9]\d*)?dD(?:([KkXxRr!])(?:(?:(?:(?<=[Rr!])(<=|>=))?([1-9]\d*))?)|(<=|>=)([1-9]\d*)(?:[fF](<=|>=)([1-9]\d*))?)?)
2
u/SpicerXD Sep 15 '26
I wrote this sed command once:
2
u/edave64 Sep 15 '26
There is nothing difficult about these. They both bundle three different types of token. Numbers, variables and operator symbols.
The first one only reads positive numbers, the second one supports negative numbers and e-notation.
Typically, if stuff gets really complex, it's a good sign regex is just the wrong tool. So the most complex regexes are the ones I write for mass search-replace in the editor, where there is no other tool.
2
u/smartgenius1 Sep 15 '26
Need a regex that detects primes for your math library?
https://imgur.com/a/qZqOXNC
2
u/JazzlikeWishbone938 Sep 15 '26
Instead of a regex I'd tokenize all the characters then use an interpreter with recursion for processing bracket content.
2
u/martmists Sep 16 '26
For XML I had a few:
Then there's cleanup of unluac output:
And for scraping Nintendo Today's API:
And some UUID matching I think?
2
u/MushroomSaute Sep 16 '26
I like this one purely because of how much I had to escape in vim, and because it's just so... vertical:
Unescaped (or rather, dropping vim magic for readability):
Basically, I wanted to match just one instance of each unique tuple that had no pipes before it, like
So, from the start of the line
^, match everything that's not a pipe[^|]*, until we match a parentheses pair\([^)]*\)-- knowing the data inside the tuple wouldn't have)-- and capture it as group 1(). Then, check all following characters on all lines(.|\n)*, and if capture group\1is matched again anywhere, even after a pipe now, this line no longer matches:@!. So, just the last occurrence is matched!This would have the side effect of not matching anything if the last occurrence were after a pipe, but thankfully that didn't matter for my purposes. Fixing it now, for fun, it'd be something like this:
I wouldn't put the first-pipe-check in the capture group, though, since I'd want to account for there being different whitespace, other characters, etc.; just as long as that tuple is somewhere before the first pipe a second time, it shouldn't match the current line.
1
u/beyluta Sep 15 '26
The techlead of the company I work for told me to always use regex for validation because it is more readable. I can still read conditional blocks, but I have no idea what the regexes I wrote 6 months ago even do today.
1
u/BenchEmbarrassed7316 Sep 15 '26
https://extendsclass.com/regex-tester.html
How I stopped worrying and learned to love the regular expressions.
ps I'm not an author.
1
u/pattch Sep 15 '26
I wrote a multiline URL matching regex for use in browser based terminals. It frequently broke and was a nightmare to debug.
1
u/NinjaLaserHaifisch Sep 15 '26
Not everyone seems to get the joke here
1
u/HTTP_404_NotFound Sep 15 '26
Thats, complicated??????
You have \ to escape. so...
One ore more digits followed Then... period followed by 1 or more digits, OPTIONALLY.
Followed by a pipe.
Followed by by a Upper OR lowercase Letter, OR underscore.
Followed by Another Letter, OR number, OR underscore, with 0 or more matches.
Followed by a pipe
Followed by one of these symbols: + \ - * / % ^ ( ) ,
Thats an easy one.
1
u/Plus-Weakness-2624 Sep 15 '26
The pattern that control jo mommas vibe-rater
1
u/mrwedders Sep 15 '26
Wrote Perl professionally for 8y, 'nuff said.
I still reach for regex more than most people I work with because it feels very natural to me now. That said, if I have to do any lookaheads or any of the real nonsense I still need the manual.
1
u/-Redstoneboi- Sep 15 '26
you can't parse balanced parentheses with one regex and no outer logic
1
u/Qwert-4 Sep 16 '26
You forgot special math symbols, e.g. ÷× −√
1
u/JollyJuniper1993 Sep 16 '26
Gotta be the challenge on alf.nu to write a Regex that checks whether a game of TicTacToe is won.
1
u/MooseBoys Sep 16 '26
So `42.` isn't a proper expression? Gtfo
1
u/Zantier Sep 16 '26
Scary? Both of these are just "number or word or symbol".
1
u/questron64 Sep 16 '26
Regex can get pretty hairy if you try to cram it all on one line. You can use the enter key, you can add indentation. It become 1000x more readable that way.
1
u/rdrunner_74 Sep 16 '26
I had to inject error handling with parameter logging into about 1000+ visual basic classes and modules. (Into each function/method)
They wanted it for every function that did not yet have its own error handling.
I learned a LOT about the structure of a visual basic file... And in the end I actually made it and the whole thing compiled and did what it was supposed to do. The "regexp" was about 3 screens long, and I am sure it was the main contributor for my hair loss. But I now know the difference between a greedy and a non greedy match and see regexp more like a programming language with a horrible syntax.
1
u/SmileyFace799 Sep 16 '26
Something something e-mail parsing regex
1
u/Interesting_Buy_3969 Sep 16 '26
Wait until you have to write a regex to parse HTML.
1
u/MarinoAndThePearls Sep 16 '26
Have you ever tried doing a complete e-mail validation regex? Pretty much impossible.
1
u/jolharg Sep 17 '26
I don't even remember but i made one like 51 chars long once for taking html content or possibly just compressing html into a structure where no libraries existed
1
u/elliottcable Sep 17 '26
I wrote a custom parsing, highlighting, and rendering engine as a side-project to help me decompose and keep track of some genuinely nightmare-tier (~200+ LoC) regexen, a very long time ago.
To be clear, not 200 lines of some other language using regular expressions. Individual compound expressions written in their own files to make editing and understanding them easier.
(These were highlighting-engine grammars for a really weird macOS-only code editor back then, named Espresso; I forget most of the details, but I have some cool screenshots buried somewhere of some insanely complex nested regexen.)
1
u/matthijspc Sep 17 '26
Any regex scares me
1
u/gutentight69420 Sep 19 '26
I've concluded that regex should almost never be used in production code. It can be handy as a search tool in text editors. However, the number of cases where regex is actually the correct tool for the job (parsing regular languages) is extremely limited. Extending regex with backreferences and other features detaches it from it's theoretical framework and generally has performance issues. Even when used appropriately, regex expressions quickly become a write-only mess with only modest complexity. You're almost always better off using a proper grammar and parser generator than regex.
0
u/nekro_neko Sep 16 '26
No it doesn't. It doesn't even check for an equal sign. You're trying to get people to do your homework for you, aren't you?
0
u/WFEpeteypopoff Sep 15 '26
This looks the same as every regex ive ever seen - gibberish!