
Regex that only matches itself - biot
http://codegolf.stackexchange.com/a/31863
======
ninkendo
Mostly unrelated, but I use the opposite trick to ensure that the "grep"
process itself doesn't show up when I "ps | grep" for a process.

Something like:

    
    
        ps -ef | grep "myprogra[m]"
    

Is still a regex that matches the string "myprogram", but it doesn't match
_itself_ , so the "grep myprogram" doesn't show up in the output. Easier than
doing " | grep -v grep" or similar.

~~~
daveFNbuck
I just use pgrep for this now.

~~~
kalleboo
Not all platforms have pgrep, so I had to look up a trick like that in GP this
weekend

------
usmannk
This is ridiculous. How does one go about deriving something like this? Really
impressive.

~~~
jrheard
If you think that's crazy, check out
[https://www.infoq.com/presentations/miniKanren](https://www.infoq.com/presentations/miniKanren)
at the 31:30 mark. These two guys teach their logic programming system a
subset of scheme, then they can run it "backwards" to find quines - programs
that evaluate to themselves.

~~~
ndr
That is amazing. I don't want to spoil the fun but I highly recommend that
video!

------
jzox
Reminds me of a quine - a non-empty computer program which takes no input and
produces a copy of its own source code as its only output

[https://en.m.wikipedia.org/wiki/Quine_(computing)](https://en.m.wikipedia.org/wiki/Quine_\(computing\))

~~~
fdej
It is literally a quine, viewed as a program in a language where (for example)
the code consists of a regular expression and the output is the sequence of
all strings matching that regular expression.

------
CPLX
I wish I was as smart as these people.

~~~
valarauca1

         Everybody is a Genius. But if you judge a fish by
         its ability to climb a tree, it will live its whole
         life believing that it is stupid.
    
         - Albert Einstein

~~~
hyperpape
Probably not Einstein [http://quoteinvestigator.com/2013/04/06/fish-
climb/](http://quoteinvestigator.com/2013/04/06/fish-climb/) (not that it
matters in any deep way).

------
zitterbewegung
This is probably a stupid question but what is the minimal formal language
that has an accepting path as a statement in the language?

~~~
gchpaco
A formal language is basically just a mathematical set of acceptable strings
made up of symbols in a (typically finite) alphabet; thus the smallest is
probably the empty set, or if you insist on an accepting path, a set
containing only the empty string.

The interesting part comes up when you want to match an infinite set of
strings with an algorithm. Probably the simplest such algorithm would be
"regardless of input, accept" which isn't exactly useful but would suffice.

It's dissatisfying to have an algorithm that puts weird, arbitrary
restrictions on composing languages; for example it's usually the case that if
you take a language L1 and a language L2 that are both acceptable to the
algorithm, the concatenation (for every string in L1 and every string in L2,
the concatenation of their strings is in the new language) language is usually
acceptable to the algorithm.

Some commonly used languages do not have all of these properties; in
particular the intersection of two context-free languages may not be a CFL,
nor the complement. Deterministic context free languages are even more
restrictive. You seem to need to give some things up as you move up the
language hierarchy in power; in particular string homomorphism and
intersection seem to be mutually exclusive in languages more powerful than
regular expressions.

If you're interested, the theory of abstract families of languages has been
studied, although I do not know a lot about it myself.

------
mepcotterell
I think I might be missing something. Wouldn't something like "a" be a valid
1-byte regular expression that only matches instances of "a"?

~~~
idbehold
> NOTE, delimiters must be included

Your regex is actually /a/ which does not match the string "/a/".

~~~
takeda
I would say that adding slashes is quite arbitrary constraint, and it is
really language specific syntax that is limited to minority of languages (I
believe it was introduced in Perl). If you do regexp in Java, Python, C you
don't use slashes.

Edit: looks like slashes weren't even used in the example.

~~~
mcpherrinm
It's a pretty boring question if you don't make that requirement, though. The
whole exercise is arbitrary, so it doesn't bother me.

------
singularity2001
Completely unrelated:
[http://codegolf.stackexchange.com/questions/99026/build-
me-a...](http://codegolf.stackexchange.com/questions/99026/build-me-a-brick-
wall) (using Trumpscript)

------
tedunangst
funny how many times this needed to be submitted before it stuck.
[https://news.ycombinator.com/from?site=stackexchange.com](https://news.ycombinator.com/from?site=stackexchange.com)

~~~
i336_
Wow, and none of them even have [dupe] on them.

HN's story ranking system is undisclosed to prevent startups and/or VCs from
gaming things AFAIK, but I'm wondering if it pushes things up based on time of
day.

Alternatively, maybe the people who check /new are only around at certain
times.

In any case, I'm definitely checking /new a lot more myself. Most of the
things I've posted haven't "stuck" either, I realize just how many people this
seems to be hitting.

~~~
pbhjpbhj
>I'm wondering if it pushes things up based on time of day. //

What do you mean by that? I don't think HN sniffs location so hour would it
even work with a global audience?

~~~
i336_
That is an incredibly good point, I certainly wasn't thinking clearly while I
was figuring that out, hah

I remember seeing someone do some data analysis of all of HN and noted that
there was a certain time of day that always seemed to be consistently upvoted
the most. I think I was overextrapolating that data, especially considering
I've no idea what the article was called now so I couldn't review it.

------
dmalvarado
Straight-up wizardry.

