75
u/RDfromMtHare May 07 '21
Quick! Seal the facility! Cut all network connections!
5
u/PranshuKhandal May 07 '21
search and delete all occurences
6
May 07 '21
But how can we detect all occurences?
8
u/PranshuKhandal May 07 '21
we need to make a regular expression for searching irregular expression
4
May 07 '21
As long as irregular expressions aren't anything like HTML, count me in.
→ More replies (2)
36
u/jfb1337 May 07 '21
The "regexes" offered in most programming languages are already irregular.
11
May 07 '21
concatenation, alternation, repetition is all we should need, but i'd ask for sets and negated sets so we can deal with unicode without going mad
→ More replies (2)2
u/Kered13 May 08 '21
Sets and negated sets are both forms of alternations, so they are fine. Forward references, back references, and look aheads are what make a grammar irregular.
→ More replies (1)
34
23
u/halfphysicshalfmath May 07 '21
Waiting for someone to link an obligatory xkcd comic on regex
27
18
58
u/lady_Kamba May 07 '21
The next step up from regular expressions would be context free expressions.
43
u/tomthecool May 07 '21
Technically the things we refer to as "regex" are context-free expressions.
For example: Look-aheads, back-references and subexpression calls are not, in terms of the chomsky hierarchy, "regular".
10
u/lady_Kamba May 07 '21
This makes sense, had I thought about it instead of assuming that regular expression had regular grammar, I might have come to the same conclusion.
→ More replies (1)1
u/Kered13 May 08 '21
You should avoid using those if you can though, as they cause the runtime to be exponential instead of linear.
→ More replies (2)16
May 07 '21
Sometimes I think I'm smart, and sometimes I try to understand a Wikipedia page about chomsky hierarchy.
12
May 07 '21
It's not about being smart, you probably just need previous knowledge, like already understanding Chomsky hierarchy before reading the Wikipedia. Most of the text there is only reference, not very good introductions.
2
May 07 '21
I'm glad to hear that, because that page made 0 sense to me.
4
1
May 08 '21
wait, anarchist grandpa contributed to the CS world too? holy cow
1
u/Kered13 May 08 '21
He actually started as a linguist. He created the Chomsky Hierarchy as part of his work on formal grammars, in an attempt to find a universal grammar for human language. This work found new application in computer science when people started writing parsers for programming languages.
7
5
3
u/phpdevster May 07 '21
regular expressions vs this
*insert Pam Beesly "they're the same picture" meme*
3
5
u/HanlonsDullBlade May 07 '21
Perfectly regular if you convert the string to spanish and parse it as like Hebrew....
2
1
1
1
1
1
1
1
1
u/hk2k1 May 07 '21
Guys im having a hard time learning regex .. is there any website to learn from ?
2
May 07 '21
Idk about specific websites with best info on it, but I highly recommend a live parser for it like https://regex101.com/
It'll allow you to experiment and get a grasp on things without having to like recompile or contrive a test case over and over in your application.
1
1
1
1
1
1
1
1
716
u/Vardy May 07 '21
After so many years of doing regex, I still can't tell if thats valid or not.